zoukankan      html  css  js  c++  java
  • The message received from the server could not be parsed 错误解决方法

    因为用的是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解释:打开非模式页面

  • 相关阅读:
    java中会存在内存泄漏吗,请简单描述?
    垃圾回收器的基本原理是什么?垃圾回收器可以马上回收内存吗?有什么办法主动通知虚拟机进行垃圾回收?
    SpringMvc的控制器是不是单例模式,如果是,有什么问题,怎么解决?
    SpringMVC怎么样设定重定向和转发的?
    Spring MVC的异常处理 ?
    如果前台有很多个参数传入,并且这些参数都是一个对象的,那么怎么样快速得到这个对象?
    Spring是什么?
    SpringMvc用什么对象从后台向前台传递数据的?
    SpringMvc中函数的返回值是什么?
    BeanFactory和ApplicationContext有什么区别?
  • 原文地址:https://www.cnblogs.com/WangJinYang/p/2778011.html
Copyright © 2011-2022 走看看