Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器收到的消息-Gridview中的“链接"按钮 [英] Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed - Link Button within Gridview

查看:107
本文介绍了Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器收到的消息-Gridview中的“链接"按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究VS 2010. 我在内容页面上有一个gridview.我正在尝试从服务器下载文件.

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.

单击链接按钮将发生文件下载功能,该链接按钮位于每个单独记录的gridview内. gridview放置在更新面板中,而Script Manager放置在母版页上. 另外,我在页面上使用了引导程序.

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运行时错误:Sys.WebForms.PageRequestManagerParserErrorException: 从服务器收到的消息无法解析.

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.

我尝试使用"PostBackTrigger".但这不能解决问题. 我已经引用了下面的链接,但未提供上述建议的解决方案

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

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.

设计-

<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();
}

任何建议/建议都将不胜感激. 预先感谢.

Any advice / suggestions is greatly appreciated. Thanks in advance.

推荐答案

问题是这些控件在模板中,因此您无法直接引用它们.使用RowDataBound事件并以编程方式为按钮分配一个触发器.

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.

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);
    }
}

这篇关于Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器收到的消息-Gridview中的“链接"按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆