Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 121 Vote(s) - 3.73 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed

#1
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 am 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."

Reply

#2
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....
}
Reply

#3
I had the same error, then I tried **`<asp:PostBackTrigger ControlID="xyz"/>`** instead of **AsyncPostBackTrigger** .This worked for me. It is because we don't want a partial postback.
Reply

#4
1- **Never** use Response.Write.

2- I put the code below after create (not in Page_Load) a LinkButton (dynamically) and solved my problem:


ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterPostBackControl(lblbtndoc1);
Reply

#5
In my case, the problem was caused by some **Response.Write** commands at **Master Page** of the website (code behind). They were there only for debugging purposes (that's not the best way, I know)...
Reply

#6
Add this to you PageLoad and it will solve your problem:

ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterPostBackControl(this.lblbtndoc1);
Reply

#7
[This][1] worked for me too, but with an addition (below).

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

I was registering a script on my button to click on another button after its event was finished processing. In order for it to work, I had to remove the other button from the Update Panel (just in case somebody faces the same problem).


[1]:

[To see links please register here]

Reply

#8
I added the control to the `Triggers` tag in the update panel:

</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="exportLinkButton" />
</Triggers>
</asp:UpdatePanel>

This way the exportLinkButton will trigger the UpdatePanel to update.
More info [here][1].


[1]:

[To see links please register here]

Reply

#9
For my VB.Net Friends -

Dim scriptManager As ScriptManager = scriptManager.GetCurrent(Me.Page)
scriptManager.RegisterPostBackControl(Me.YourButtonNameHere)
Reply

#10
What worked for me was setting aspnet:MaxHttpCollectionKeys to a high value on appSettings tag on the inetpub VirtualDirectories\443\web.config file:

<configuration>
<appSettings>
<add key="aspnet:MaxHttpCollectionKeys" value="100000" />
</appSettings>
</configuration>
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through