簡體   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