繁体   English   中英

C#RegisterPostBackControl不适用于另一个更新面板中的Timer

[英]C# RegisterPostBackControl does not work with Timer in another update panel

在我的应用程序中,我在每行使用带有下载文件链接的asp:GridView。 为了注册回发控件,我正在使用GridView的OnRowDataBound属性。

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" >
...
    <asp:GridView ID="folderContentGrid" runat="server" AutoGenerateColumns="False"
        width="100%" ShowHeaderWhenEmpty="true" CssClass="table table-hover" OnRowDataBound="bindDownloadAction">
        <Columns>
            <asp:TemplateField HeaderText="Action" ItemStyle-CssClass="text-center" HeaderStyle-Width="6%">
                <ItemTemplate>
                    <ul class="icons-list hide-if-no-action">
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-menu9"></i></a>
                            <ul class="dropdown-menu dropdown-menu-left fl-drp">
                                <li id="liDownloadBtn" runat="server" visible='<%# Eval("FileType").ToString().Equals("File")%>'>
                                    <asp:LinkButton ID="lnkDownloadBtn" CssClass="block-ui-click" runat="server" data-pid ='<%# Eval("UiIndex") %>' 
                                    OnClick="onClickDownloadBtn"><i class="icon-download"></i>Download</asp:LinkButton></li>
                                <li id="liDeleteFileBtn" runat="server"><asp:LinkButton ID="lnkDeleteFileBtn" runat="server" data-pid ='<%# Eval("UiIndex") %>' data-md-button="btnDeleteFileHdn" 
                                    data-md-action="DELETE" data-md-title="Delete File" data-md-message="Do you want to delete {0} '{1}'?" 
                                    data-md-message-opt-0='<%# Eval("FileType").ToString().Equals("Folder") ? "folder" : "document" %>' data-md-message-opt-1='<%# Eval("Name") %>' 
                                    OnClientClick="return confirmActionModal(this);"><i class="icon-bin"></i>Delete</asp:LinkButton></li>
                            </ul>
                        </li>
                    </ul>
                </ItemTemplate>
            </asp:TemplateField>
            <!-- Other Columns-->
        </Columns>
    </asp:GridView>
    ...
</asp:UpdatePanel>

后面的代码可在下载链接上注册回发

protected void bindDownloadAction(Object sender, GridViewRowEventArgs e)
{
    LinkButton lnkDownloadBtn = (LinkButton)e.Row.FindControl("lnkDownloadBtn");
    if (lnkDownloadBtn != null)
    {
        ScriptManager mgr = ScriptManager.GetCurrent(this.Page);
        mgr.RegisterPostBackControl(lnkDownloadBtn);
    }
}

我在主页上有另一个带有计时器的更新面板,如下所示

<asp:UpdatePanel ID="upNotificationAlertUpdatePanel" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:ListView ID="notificationAlertGrid" runat="server">
            <LayoutTemplate><ul class="media-list dropdown-content-body width-350 pt-0 blockui-alert-notifications ulNotification"><asp:PlaceHolder ID="itemPlaceholder" runat="server" /></ul></LayoutTemplate>
            <ItemTemplate>
                <li id="Li5" runat="server" class="media alert-notification">
                    <div class="media-left cs-media-mini"><span class="btn border-teal text-teal btn-flat cs-media btn-rounded btn-icon btn-sm"><i class='<%# Eval("NotyTypeIcon") %>'></i></span></div>
                    <div class="media-body">
                        ...                                         
                    </div>
                </li>
            </ItemTemplate>
        </asp:ListView>
        <asp:HiddenField ID="btnCallIntimationPresentHdn" runat="server" Value="" />
        <asp:Button ID="btnCallIntimationNotificationAction" class="btn CallIntimationNotificationAction block-ui-click hidden" data-panel="" runat="server" Text=""
            OnClick="onClickCallIntimationNotification" ValidationGroup="report" data-pid ="" data-entityrefinfo ="" data-uniqueid ="" data-message=""/>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="RefreshNotificationTimer" EventName="Tick" />
    </Triggers>
</asp:UpdatePanel>
<asp:Timer ID="RefreshNotificationTimer" runat="server" Interval="10000" OnTick="autoRefreshNotifications"></asp:Timer> 

问题-首次加载页面时,下载链接有效,我可以下载文件。 但是,一旦计时器触发了滴答事件,则下载链接将不起作用,并且浏览器控制台中的错误将降至错误以下。

ScriptResource.axd:885 Uncaught Error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.
    at Function.Error$create [as create] (ScriptResource.axd:237)
    at Sys$WebForms$PageRequestManager$_createPageRequestManagerParserError [as _createPageRequestManagerParserError] (ScriptResource.axd:665)
    at Sys$WebForms$PageRequestManager$_parseDelta [as _parseDelta] (ScriptResource.axd:1435)
    at Sys$WebForms$PageRequestManager$_onFormSubmitCompleted [as _onFormSubmitCompleted] (ScriptResource.axd:1314)
    at Array.<anonymous> (ScriptResource.axd:47)
    at ScriptResource.axd:3484
    at Sys$Net$WebRequest$completed [as completed] (ScriptResource.axd:6376)
    at XMLHttpRequest.Sys$Net$XMLHttpExecutor._onReadyStateChange (ScriptResource.axd:5996)

注意:当我将计时器间隔从10秒增加到5分钟时,便可以下载文件直到5分钟。 根据我的理解,timer的部分回发调用是从scriptmanager删除其他updatepanel的已注册回发控件,尽管updatemode都是有条件的。

任何帮助都非常感谢。

您可以尝试此代码段。 它找到嵌套页面的GridView,然后在Timer Tick上重新绑定PostBack触发器。

protected void autoRefreshNotifications(object sender, EventArgs e)
{
    //find the gridview in the contentplaceholder
    GridView gv = ContentPlaceHolder1.FindControl("folderContentGrid") as GridView;

    //loop all the rows in the gridview
    foreach (GridViewRow row in gv.Rows)
    {
        //find the linkbutton in the row using findcontrol
        LinkButton lnkDownloadBtn = (LinkButton)row.FindControl("lnkDownloadBtn");

        if (lnkDownloadBtn != null)
        {
            //bind the postback trigger to the linkbutton
            ScriptManager mgr = ScriptManager.GetCurrent(this.Page);
            mgr.RegisterPostBackControl(lnkDownloadBtn);
        }
    }
}

也可以将folderContentGrid的绑定folderContentGrid IsPostBack检查之外。 然后在每个PostBack上调用RowDataBound。 但是根据您的要求和其他代码,也可能会产生一些问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM