Last post Apr 23, 2010 01:16 PM by Chintan Dave
Apr 22, 2010 02:37 PM|dotnet_developer2010|LINK
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:UpdateProgress ID="UpdateProgress1" runat="server">
<img src="progressbar.gif" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<asp:Button ID="Button1" runat="server" Text="Export to Excel" />
<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.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
Does anybody experience the same problem? Any help is greatly appreciated
Apr 22, 2010 05:13 PM|UstesG|LINK
add this to the pages code-behind
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.
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...
Apr 23, 2010 08:45 AM|dotnet_developer2010|LINK
Any help is greatly appreciated..
Apr 23, 2010 11:49 AM|UstesG|LINK
I forgot that I add the button to export as a postbackcontrol to the scriptmanager
As ScriptManager = ScriptManager.GetCurrent(Me.Page)
Apr 23, 2010 12:26 PM|dotnet_developer2010|LINK
I added the code to the Page_load, but now the progress bar dissappears.
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
or add button in postbacktrigger.
other way is
you can disable the error by disabling the request validation.On top of the webform add:
also read this article for more information abt this error;
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
Apr 23, 2010 01:16 PM|Chintan Dave|LINK
one is just remove update panel and upade progress bar.
so ur responce.write function works and page not give any error.