前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >The message received from the server could not be parsed 错误解决方法

The message received from the server could not be parsed 错误解决方法

作者头像
DougWang
发布2020-02-18 16:16:13
6090
发布2020-02-18 16:16:13
举报
文章被收录于专栏:java跬步java跬步

因为用的是Ajax的  ScriptManager + UpdatePanel控件

所以调用Response.Write(),Page.RegisterStartScript()等方法,就不行了

需要调用Ajax本身的ScriptManager.RegisterStartupScript()方法;

具体格式为:

System.Web.UI.ScriptManager.RegisterStartupScript(Control control, Type type, string key,string script, bool addScriptTags)

调用方式为:

System.Web.UI.ScriptManager.RegisterStartupScript(this,this.GetType(),"KEY","alert('ss')",true);

现在项目中用到的列出几个,以后可能用到的:

AjaxFunc.cs

/// <summary> /// MSG 的摘要说明 /// </summary> public static class AjaxFunc {     /// <summary>     /// 弹出对话框     /// </summary>     /// <param name="ps"></param>     /// <param name="strName"></param>     /// <param name="strMsg"></param> public static void MessageBox(Page ps, string strName, string strMsg)     {         ScriptManager.RegisterClientScriptBlock(ps, ps.GetType(), strName, "alert('" + strMsg + "')", true);     }

    /// <summary>     /// 加载网页     /// </summary>     /// <param name="ps"></param>     /// <param name="strName"></param>     /// <param name="strUrl"></param> public static void OpenUrl(Page ps,string strName,string strUrl)     {         System.Web.UI.ScriptManager.RegisterStartupScript(ps, ps.GetType(), strName, "window.location.href='" + strUrl + "';", true);     }

    /// <summary>     /// 弹出网页     /// </summary>     /// <param name="ps"></param>     /// <param name="strName"></param>     /// <param name="strUrl"></param> public static void OpenModelUrl(Page ps,string strName,string strUrl)     {         //System.Web.UI.ScriptManager.RegisterStartupScript(ps, ps.GetType(), strName, "window.showModalDialog ('" + strUrl + "', 'newwindow', 'height=100, width=400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no');", true);         System.Web.UI.ScriptManager.RegisterStartupScript(ps, ps.GetType(), strName, "window.showModalDialog ('" + strUrl + "', 'newwindow', 'dialogHeight:650px, dialogWidth:300px, toolbar=no, menubar=no, resizable=no, location=no, status=no');", true);     }

    /// <summary>     /// 弹出网页     /// </summary>     /// <param name="ps"></param>     /// <param name="strName"></param>     /// <param name="strUrl"></param>   public static void OpenModelUrl(Page ps, string strName, string strUrl,int width, int height)     {         //System.Web.UI.ScriptManager.RegisterStartupScript(ps, ps.GetType(), strName, "window.showModalDialog ('" + strUrl + "', 'newwindow', 'height=100, width=400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no');", true);         System.Web.UI.ScriptManager.RegisterStartupScript(ps, ps.GetType(), strName, "window.showModalDialog ('" + strUrl + "', 'newwindow', 'dialogHeight:" + height.ToString() + "px; dialogWidth:" + width.ToString() + "px; toolbar:no; resizable:no; location:no; status:no;help:no;scroll:no;');", true);     }

    /// <summary>     /// 弹出网页+状态栏     /// </summary>     /// <param name="ps"></param>     /// <param name="strName"></param>     /// <param name="strUrl"></param>   public static void OpenModelUrl_EX(Page ps, string strName, string strUrl, int width, int height)     {         //System.Web.UI.ScriptManager.RegisterStartupScript(ps, ps.GetType(), strName, "window.showModalDialog ('" + strUrl + "', 'newwindow', 'height=100, width=400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no');", true);         System.Web.UI.ScriptManager.RegisterStartupScript(ps, ps.GetType(), strName, "window.showModalDialog ('" + strUrl + "', 'newwindow', 'dialogHeight:" + height.ToString() + "px; dialogWidth:" + width.ToString() + "px; toolbar:no; resizable:no; location:no; status:yes;help:no;scroll:no;');", true);     }

    /// <summary>     /// 弹出网页     /// </summary>     /// <param name="ps"></param>     /// <param name="strName"></param>     /// <param name="strUrl"></param>   public static void OpenModelUrl_DW(Page ps, string strName, string strUrl)     {         //System.Web.UI.ScriptManager.RegisterStartupScript(ps, ps.GetType(), strName, "window.showModalDialog ('" + strUrl + "', 'newwindow', 'height=100, width=400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no');", true);         System.Web.UI.ScriptManager.RegisterStartupScript(ps, ps.GetType(), strName, "window.showModalDialog ('" + strUrl + "', 'newwindow', 'dialogHeight:700px, dialogWidth:300px, toolbar=no, menubar=no, resizable=no, location=no, status=no');", true);     }     /// <summary>     /// 关闭模式网页     /// </summary>     /// <param name="ps"></param> public static void CloseModalUrl(Page ps)     {         System.Web.UI.ScriptManager.RegisterStartupScript(ps, ps.GetType(), "", "window.close();", true);     }

    /// <summary>     /// 使用AJAX操作Response.Write     /// </summary>     /// <param name="control"></param>     /// <param name="type"></param>     /// <param name="key"></param>     /// <param name="script"></param>     /// <param name="addScriptTags"></param> public static void ResponseWrite(Control control, Type type, string script, bool addScriptTags)     {         System.Web.UI.ScriptManager.RegisterStartupScript(control, type, "NULL", script, addScriptTags);     }

方法的调用:

AjaxFunc.ResponseWrite(this, this.GetType(), "alert('请登录后再使用该系统!');parent.document.location.href('../default.aspx');", true);

JS解释:

alert('请登录后再使用该系统!');弹出消息框

parent.document.location.href('../default.aspx');打开指定页

AjaxFunc.MessageBox(this, "Error", "输入旧密码不能为空!");

JS解释:弹出消息框

AjaxFunc.OpenModelUrl_EX(this.Page, "", "ShowCurveLine.aspx", 840, 550);

JS解释:打开模式页面

AjaxFunc.OpenModelUrl_EX(this.Page, "", "ShowCurveLine.aspx", 840, 550);

JS解释:打开非模式页面

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2012-11-19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档