简体   繁体   English

Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器收到的消息-Gridview中的链接按钮

[英]Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed - Link Button within Gridview

I am currently working on VS 2010. I have a gridview on my content page. 我目前正在使用VS2010。我在内容页面上有一个gridview。 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. 单击链接按钮会发生文件下载功能,该链接按钮位于每个单独记录的gridview内。 The gridview is placed within an update panel and the Script Manager is placed on the master page. gridview放置在更新面板中,而Script Manager放置在母版页上。 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 单击带有gridview的链接按钮时,显示以下错误

JavaScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. JavaScript运行时错误:Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器收到的消息。

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". 我尝试使用“ 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 我已经引用了以下链接,但未提供上述建议的解决方案

Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器收到的消息

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. 提前致谢。

The problem is that those controls are in a template so you cannot reference them directly. 问题在于这些控件在模板中,因此您无法直接引用它们。 Use the RowDataBound event and assign the buttons a trigger programatically. 使用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.

相关问题 Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器收到的消息 - Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed 显示pdf时出错:Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器收到的消息 - Error when displaying pdf: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed 获取错误-SCRIPT5022:Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器收到的消息 - Getting error - SCRIPT5022: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed Sys.WebForms.PageRequestManagerParserErrorException - Sys.WebForms.PageRequestManagerParserErrorException Sys.WebForms.PageRequestManagerParserErrorException - Sys.WebForms.PageRequestManagerParserErrorException 未捕获的Sys.WebForms.PageRequestManagerParserErrorException - Uncaught Sys.WebForms.PageRequestManagerParserErrorException UpdatePanel回发错误:Sys.WebForms.PageRequestManagerParserErrorException - UpdatePanel Postback Error: Sys.WebForms.PageRequestManagerParserErrorException 如何禁用 Sys.WebForms.PageRequestManagerParserErrorException - how to disable Sys.WebForms.PageRequestManagerParserErrorException 是否可以在客户端捕获错误“ Sys.WebForms.PageRequestManagerParserErrorException”? - Is it possible to catch error “Sys.WebForms.PageRequestManagerParserErrorException” on the client side? ASP.NET Ajax 错误:Sys.WebForms.PageRequestManagerParserErrorException - ASP.NET Ajax Error: Sys.WebForms.PageRequestManagerParserErrorException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM