2012年3月26日月曜日

Response.Write inside Updatepanel Beta 2

Hi,

I have a button inside a updatepanel, when the client click the button he can download a PDF. Everything works perfectly outside the update panel but not inside it. I got the next error message:

Sys.Webforms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error is when the response is modified by calls to Response.Write...

I really appreciate any help.

Thanks,

Jaime

My code:

PrivateSub ShowPdf(ByVal strPathAsString)

Response.ContentType =

"application/x-download"

Response.AddHeader(

"Content-Disposition","filename=YourPdf.pdf")

Response.WriteFile(strPath)

Response.End()

End Sub

<%@dotnet.itags.org.PageLanguage="VB"AutoEventWireup="false"CodeFile="Resultados.aspx.vb"Inherits="Resultados" %>

<%@dotnet.itags.org.RegisterAssembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

Namespace="Microsoft.Web.UI"TagPrefix="asp" %>

<%

@dotnet.itags.org.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="AjaxToolKit" %>

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">

.............

<

asp:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><tablestyle="width: 840px"><tr><tdstyle="width: 762px; height: 153px;"><AjaxToolKit:RoundedCornersExtenderID="RoundedCornersExtender1"runat="server"TargetControlID="TitlePanel1"Radius="10"></AjaxToolKit:RoundedCornersExtender><AjaxToolKit:CollapsiblePanelExtenderID="CollapsiblePanelExtender1"runat="server"Collapsed="true"SuppressPostBack="false"TargetControlID="ContentPanel1"ExpandControlID="Panel1"CollapseControlID="Panel1"imageControlID="image1"ExpandedImage="~/images/collapse_blue.jpg"CollapsedImage="~/images/expand_blue.jpg"></AjaxToolKit:CollapsiblePanelExtender>............

<

asp:PanelID="ContentPanel1"runat="server"CssClass="collapsePanel"Height="0"Width="728px"><tablestyle="width: 728px"><tr><tdstyle="width: 93px; height: 4px"><asp:ButtonID="Button1A"runat="server"Font-Bold="True"Font-Size="X-Small"ForeColor="Crimson"Text="Get Your PDF"Width="224px"/></td>

Hi,

After a while I have found a workaround for the problem I posted, so I am posting this workaround here in case someone else have the same problem:

Basically I have include a second button (button2) outside the control panel. Once the first button (button1, the one inside the updatepanel) is clicked it fire the next javascript:

<input type="submit" name="Button1" value="Button" onclick="javascript:document.getElementById('button2').click() ;" id="Button1" /><br />

So button1 "clicks" button2 (that is the one outside the updatepanel) and this second button is the one that get the PDF file.

To include the javascript you just need to include the next line (in vb) in the "load" of the page:

button1.Attributes.Add(

"onclick","javascript:document.getElementById('button2').click() ;")

Now i am looking for a way to hidde button2 (notice that in order to click it you can not set visible to false).

Hope this can help someone.

Best,

Jaime

0 件のコメント:

コメントを投稿