I am currently working on VS 2010. I have a gridview on my content page. I am trying to download a file from the server.
The file downloading functionality happens on the click of a link button which is placed within the gridview for each individual record. The gridview is placed within an update panel and the Script Manager is placed on the master page. Also, i have made use of bootstrap on my page.
On the click of the link button withing the gridview the following error is displayed
JavaScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.
I have searched the internet for solutions but could not find any fix. I came across links where the buttons where placed outside the grid and a similar issue was faced.But, did not find it helpful.
I have tried with using a "PostBackTrigger". But that does not fix the issue. I have referred the below link but it does not provide a solution to the issue suggested above
I have also referred other links but could not find a fix to the problem. Also removing the Update Panel is not an option.
I am placing the related design and code of my page.
Design -
<div class="col-xs-12 form-group">
<div class="table-responsive">
<asp:UpdatePanel ID="updPnlErrorDownload" runat="server" UpdateMode="Conditional">
<%--<Triggers>
<asp:AsyncPostBackTrigger ControlID="lnkLogFiles"/>
</Triggers>--%>
<ContentTemplate>
<asp:GridView ID="gvLogFilesDownload" runat="server"
AutoGenerateColumns="false" AllowPaging="true"
EmptyDataText="No Data Found" Width="100%"
CssClass="table table-striped table-bordered table-hover" PageSize="10"
onpageindexchanged="gvLogFilesDownload_PageIndexChanged"
onrowcommand="gvLogFilesDownload_RowCommand"
onrowcreated="gvLogFilesDownload_RowCreated">
<Columns>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:Label ID="lblDate" runat="server" Text='<%#Eval("Date") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Log Files">
<ItemTemplate>
<asp:LinkButton ID="lnkLogFiles" runat="server" Text='<%#Eval("Log Files") %>' Font-Underline="true" CommandName="Download" CommandArgument="<%#((GridViewRow)Container).RowIndex %>" OnClick="lnkLogFiles_Click"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
No Record Available</EmptyDataTemplate>
</asp:GridView>
</ContentTemplate>
<Triggers>
<%--<asp:PostBackTrigger ControlID="lnkLogFiles" />--%>
<%-- <asp:PostBackTrigger ControlID="gvLogFilesDownload$lnkLogFiles" />--%>
</Triggers>
</asp:UpdatePanel>
</div>
</div>
Code -
protected void lnkLogFiles_Click(object sender, EventArgs e)
{
LinkButton lnkBtnDownload = sender as LinkButton;
string file = lnkBtnDownload.Text;
//string sPath1 = Server.MapPath(file);
string sPath = Server.MapPath("~/ErrorLog/" + file);
//Response.ContentType = "APPLICATION/OCTET-STREAM";
Response.ContentType = "APPLICATION/pdf";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.IO.Path.GetFileName(sPath));
Response.TransmitFile(sPath);
Response.End();
}
Any advice / suggestions is greatly appreciated. Thanks in advance.