I use a Gridview inside an UpdatePanel. In that Gridview I use a LinkButton (I have the same problem with an imageButton) for the CommandArgument and try to download a pdf file when the user clicks.
It was tricky to get the Button running in that UpdatePanel but all seems fine. The user clicks the Button and I get the correct ID with the CommandArgument. With this ID I try to Response the pdf file but getting the error:
0x800a139e - JavaScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.
The pdf file is on the server, with an button outside the UpdatePanel I get the right pdf file. So what to I have to change to get this inside the UpdatePanel running? Thanks
Gridview:
<asp:TemplateField HeaderText="" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:LinkButton ID="Fehlermeldung" runat="server" CommandArgument='<%#Eval("ID")%>' OnClick="Fehlermeldung_Click1">
<asp:Image ID="Fehler" ImageUrl="~/images/fehlermeldung.png" ToolTip="Fehlermeldung anzeigen" runat="server" />
</asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
Code behind:
protected void Fehlermeldung_Click1(object sender, EventArgs e)
{
string id = ((LinkButton)sender).CommandArgument;
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.Clear();
Response.AppendHeader("Content-Disposition", "attachment;Filename=Fehlermeldung_" + id + ".pdf");
Response.TransmitFile(Page.MapPath(@"App_Data\Fehlermeldung_" + id + ".pdf"));
Response.End();
}
The problem is your
Fehlermeldunglink button is contained insideTemplateField, hence you cannot directly reference it like normalLinkButtondoes.You should handle
RowDataBoundevent of theGridViewto find the link button by its control name and put button postback triggers programmatically there usingRegisterPostBackControl()(GridViewNameis your grid view ID):ASPX Markup
Code behind
Reference:
Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed