I have an export to excel functionality on my web application. WHen the user clicks the "Export to Excel" button, the file is created and it will ask the user to open it or save it to their local machine.
Since the file creation process takes a long time, I added the ajax update progress control. SO now, as soon as the user clicks the "Export to Excel" button, the progress bar image shows up, but after the file is created, I get the following error.
Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.
I know that, if we use Response.write in the code behind, we get this error. But I have to use Response.Write because I am presenting the user with a prompt to save or open the newly created file. Is there any other way to do this?
Dim stringWrite As New System.IO.StringWriter
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
Dim dg As New System.Web.UI.WebControls.GridView
dg.DataSource = dv
dg.DataBind()
dg.RenderControl(htmlWrite)
Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As System.Web.UI.Control)
'confirms that an HtmlForm control is rendered for the
'specified ASP.NET server control at run time.
End Sub
Please Mark as Answer if You Find Useful!
But don't expect me to do your job!
you can not use responce.write in aspx that having update panel bcuz update panel not allow to render the page.so it is giving error.
So You can put the code to generate the data in an
HTTPHandler.
or add button in postbacktrigger.
other way is
you can disable the error by disabling the request validation.On top of the webform add:
enableEventValidation="false"
also read this article for more information abt this error;
None
0 Points
17 Posts
downloading a file and updateprogress
Apr 22, 2010 02:37 PM|dotnet_developer2010|LINK
Hello All,
I have an export to excel functionality on my web application. WHen the user clicks the "Export to Excel" button, the file is created and it will ask the user to open it or save it to their local machine.
Since the file creation process takes a long time, I added the ajax update progress control. SO now, as soon as the user clicks the "Export to Excel" button, the progress bar image shows up, but after the file is created, I get the following error.
Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.
I know that, if we use Response.write in the code behind, we get this error. But I have to use Response.Write because I am presenting the user with a prompt to save or open the newly created file. Is there any other way to do this?
The following is the aspx code.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<img src="progressbar.gif" />
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Export to Excel" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" > </gridview> ...
My button_click code is as follows
Dim ds As New DataSet
ds = GetData()
Dim dt As DataTable = ds.Tables(0)
Dim dv As DataView = New DataView(dt)
Response.Clear()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", "attachment; filename=myexcel.xls")
Dim stringWrite As New System.IO.StringWriter
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
Dim dg As New System.Web.UI.WebControls.GridView
dg.DataSource = dv
dg.DataBind()
dg.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString)
Response.Flush()
Response.End()
Does anybody experience the same problem? Any help is greatly appreciated
Thanks
DD
Participant
1470 Points
554 Posts
Re: downloading a file and updateprogress
Apr 22, 2010 05:13 PM|UstesG|LINK
add this to the pages code-behind
But don't expect me to do your job!
None
0 Points
17 Posts
Re: downloading a file and updateprogress
Apr 22, 2010 05:29 PM|dotnet_developer2010|LINK
--Ustes, Thanks for the reply
I added the method that you sent me. But I still get the same error...
None
0 Points
17 Posts
Re: downloading a file and updateprogress
Apr 23, 2010 08:45 AM|dotnet_developer2010|LINK
Does anybody know of any other ways to accomplish this, for e.g using javascript??
Any help is greatly appreciated..
Thanks
Participant
1470 Points
554 Posts
Re: downloading a file and updateprogress
Apr 23, 2010 11:49 AM|UstesG|LINK
I forgot that I add the button to export as a postbackcontrol to the scriptmanager
Dim sm As ScriptManager = ScriptManager.GetCurrent(Me.Page)
sm.RegisterPostBackControl(lnkExportExcel)
But don't expect me to do your job!
None
0 Points
17 Posts
Re: downloading a file and updateprogress
Apr 23, 2010 12:26 PM|dotnet_developer2010|LINK
I added the code to the Page_load, but now the progress bar dissappears.
Contributor
2360 Points
727 Posts
Re: downloading a file and updateprogress
Apr 23, 2010 12:32 PM|Chintan Dave|LINK
you can not use responce.write in aspx that having update panel bcuz update panel not allow to render the page.so it is giving error. So You can put the code to generate the data in an HTTPHandler.
or add button in postbacktrigger.
other way is you can disable the error by disabling the request validation.On top of the webform add: enableEventValidation="false"
also read this article for more information abt this error;
Sys.WebForms.PageRequestManagerParserErrorException - what it is and how to avoid it
http://napsterchintan.blogspot.com/
None
0 Points
17 Posts
Re: downloading a file and updateprogress
Apr 23, 2010 12:44 PM|dotnet_developer2010|LINK
Thanks Chintan for the reply.
I am new to Ajax, and thanks for the information.
Is there any other way to accomplish what I am trying to achieve? In breif, I am trying to achieve the following
1. User clicks the "Export To Excel" button
2. User sees a progress bar (Since the file creation takes some time, around a minute or two)
3. Once the file creation is complete, user will get the usual File download prompt, to open, save or cancel
THanks
Contributor
2360 Points
727 Posts
Re: downloading a file and updateprogress
Apr 23, 2010 01:16 PM|Chintan Dave|LINK
one is just remove update panel and upade progress bar.
use javascript progress bar. u can get this javascipt progress bar from here:
http://www.javascriptkit.com/script/script2/progressbar.shtml
so ur responce.write function works and page not give any error.
http://napsterchintan.blogspot.com/