gpt4 book ai didi

c# - Sys.WebForms.PageRequestManagerParserErrorException : The message received from the server could not be parsed

转载 作者:IT王子 更新时间:2023-10-29 03:46:41 24 4
gpt4 key购买 nike

我的页面上有一个 GridView ,我想将它导出到 Excel 工作表,下面是我为完成此任务而编写的代码,这里我已经将数据集传递给绑定(bind)网格的方法,btnExcelExport 是将网格内容导出到 Excel 工作表的按钮:-

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;
}

现在,当我调试时,我发现网格已成功绑定(bind),但在尝试将其导出到 Excel 时,出现此错误:

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

最佳答案

我解决了这个问题。当我使用 UpdatePanel 时,我在页面的 Page_Load 事件中添加了以下代码,它对我有用:

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

关于c# - Sys.WebForms.PageRequestManagerParserErrorException : The message received from the server could not be parsed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11221033/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com