Sys.WebForms.PageRequestManagerParserErrorException:从服务器收到的消息无法解析 [英] Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed

查看:1359
本文介绍了Sys.WebForms.PageRequestManagerParserErrorException:从服务器收到的消息无法解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的页面上的网格视图,我想将其导出到Excel工作表,
下面是code我写做这个任务,我在这里已经传递数据的方法,以网格结合和btnExcelExport是将导出网格内容到Excel工作表的按钮: -

 私人无效BindGridView(DataSet的DS)
{
    如果(ds.Tables.Count大于0)
    {
        如果(ds.Tables [0] .Rows.Count大于0)
        {
            GVUserReport.DataSource = DS;
            GVUserReport.DataBind();
            btnExcelExport.Visible =真;
        }
    }
}保护无效btnExcelExport_Click(对象发件人,EventArgs的发送)
{
    Response.Clear();
    Response.AddHeader(内容处置,附件;文件名= FileName.xls);
    Response.Charset的=;
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.ContentType =应用程序/ vnd.xls
    System.IO.StringWriter stringWrite =新System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter htmlWrite =新的HtmlTextWriter(stringWrite);
    GVUserReport.RenderControl(htmlWrite);
    的Response.Write(stringWrite.ToString());
    到Response.End();
}公共覆盖无效VerifyRenderingInServerForm(控制控制)
{
    返回;
}

现在,当我为我调试发现,网格成功地绑定,但试图将其导出到Excel的时候,我得到这个错误:


  

Microsoft JScript运行错误:
  Sys.WebForms.PageRequestManagerParserErrorException:消息
  从无法解析服务器收到。



解决方案

我解决了这个问题。当我使用的UpdatePanel ,我在下面的页面的Page_Load 事件code和它的工作对我来说:

 保护无效的Page_Load(对象发件人,EventArgs的发送){
  的ScriptManager的ScriptManager = ScriptManager.GetCurrent(this.Page);
  scriptManager.RegisterPostBackControl(this.btnExcelExport);
  //进一步code到这里....
}

I have a grid view on my page and i want to export it to the Excel Sheet, Below is the code i had written to do this task, here i am already passing the dataset to the method to bind the grid and btnExcelExport is the button which will export the Grid Content in to Excel Sheet :-

private void BindGridView(DataSet ds)
{
    if (ds.Tables.Count > 0)
    {
        if (ds.Tables[0].Rows.Count > 0)
        {
            GVUserReport.DataSource = ds;
            GVUserReport.DataBind();
            btnExcelExport.Visible = true;
        }
    }
}

protected void btnExcelExport_Click(object sender, EventArgs e)
{
    Response.Clear();
    Response.AddHeader("content-disposition","attachment;filename=FileName.xls");
    Response.Charset = "";
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.ContentType = "application/vnd.xls";
    System.IO.StringWriter stringWrite = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
    GVUserReport.RenderControl(htmlWrite);
    Response.Write(stringWrite.ToString());
    Response.End();
}

public override void VerifyRenderingInServerForm(Control control)
{
    return;
}

Now when i m debugging i found that the grid is binded sucessfully but when trying to export it to Excel , I'm getting this error:

"Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed."

解决方案

I fixed this issue. As I'm using UpdatePanel, I added below code in the Page_Load event of the page and it worked for me:

protected void Page_Load(object sender, EventArgs e) {
  ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
  scriptManager.RegisterPostBackControl(this.btnExcelExport);
  //Further code goes here....
}

这篇关于Sys.WebForms.PageRequestManagerParserErrorException:从服务器收到的消息无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆