[英]Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed
[英]Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed - Link Button within Gridview
我目前正在使用VS2010。我在內容頁面上有一個gridview。 我正在嘗試從服務器下載文件。
單擊鏈接按鈕會發生文件下載功能,該鏈接按鈕位於每個單獨記錄的gridview內。 gridview放置在更新面板中,而Script Manager放置在母版頁上。 另外,我在頁面上使用了引導程序。
單擊帶有gridview的鏈接按鈕時,顯示以下錯誤
JavaScript運行時錯誤:Sys.WebForms.PageRequestManagerParserErrorException:無法解析從服務器收到的消息。
我已經在互聯網上搜索了解決方案,但找不到任何解決方法。 我遇到了一些鏈接,其中的按鈕位於網格外部,並且面臨類似的問題。但是,發現它沒有幫助。
我嘗試使用“ PostBackTrigger”。 但這不能解決問題。 我已經引用了以下鏈接,但未提供上述建議的解決方案
Sys.WebForms.PageRequestManagerParserErrorException:無法解析從服務器收到的消息
我還引用了其他鏈接,但找不到解決該問題的方法。 也不能刪除更新面板。
我要放置頁面的相關設計和代碼。
設計-
<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>
代碼-
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();
}
任何意見/建議,不勝感激。 提前致謝。
問題在於這些控件在模板中,因此您無法直接引用它們。 使用RowDataBound事件並以編程方式為按鈕分配一個觸發器。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//check if the row is a datarow and not the first row
if (e.Row.RowType == DataControlRowType.DataRow)
{
//find the button with findcontrol
LinkButton lb = e.Row.FindControl("lnkLogFiles") as LinkButton;
//assign the button as a postback trigger
ScriptManager.GetCurrent(Page).RegisterPostBackControl(lb);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.