【问题标题】:Is it possible to refresh the whole page using an updateprogress?是否可以使用 updateprogress 刷新整个页面?
【发布时间】:2020-08-19 14:38:13
【问题描述】:

我正在尝试在我的页面中实现一个重新初始化按钮,该按钮链接到 UpdatePanel (AsyncPostBackTrigger)。当我点击按钮时,它会处理一个 UpdateProgress。

问题在于,由于重新初始化按钮与更新面板链接,它无法重新初始化更新面板之外的内容。

有没有办法在不为整个页面添加 UpdatePanel 的情况下对 UpdatePanel 之外的控件进行一些更改?在这种情况下,我想重新初始化 UpdatePanel 中包含的 DropDownLists、文本框和中继器。

How the page is rendered

ASPX 代码:

<body style="padding: 50px;">
    <form id="form1" runat="server">
        <asp:Label runat="server" ID="test"></asp:Label>
        <asp:HiddenField runat="server" ID="AllDemandsTypeHfi"></asp:HiddenField>
        <asp:ScriptManager runat="server" ID="ScriptManager"></asp:ScriptManager>
        <asp:Panel runat="server" CssClass="panel-page-title">Création de demande</asp:Panel>
        <asp:Panel runat="server" CssClass="panel-primary">
            <asp:Panel runat="server" CssClass="panel-heading">Configuration de la recherche</asp:Panel>
            <asp:Panel runat="server" CssClass="panel-body">
                <asp:Table runat="server">
                    <asp:TableRow ID="BankRow">
                        <asp:TableCell>
                                <asp:Label runat="server">Banque : </asp:Label>
                        </asp:TableCell>
                        <asp:TableCell>
                            <asp:DropDownList runat="server" ID="BankDdl" AutoPostBack="true" OnSelectedIndexChanged="BankDdl_SelectedIndexChanged"></asp:DropDownList>
                        </asp:TableCell>
                    </asp:TableRow>
                    <asp:TableRow>
                        <asp:TableCell>
                                <asp:Label runat="server">Famille : </asp:Label>
                        </asp:TableCell>
                        <asp:TableCell>
                            <asp:DropDownList runat="server" ID="FamilyDdl" AutoPostBack="true" OnSelectedIndexChanged="FamilyDdl_SelectedIndexChanged"></asp:DropDownList>
                        </asp:TableCell>
                    </asp:TableRow>
                    <asp:TableRow>
                        <asp:TableCell>
                                <asp:Label runat="server">Motif : </asp:Label>
                        </asp:TableCell>
                        <asp:TableCell>
                            <asp:DropDownList runat="server" ID="MotiveDdl" AutoPostBack="true" OnSelectedIndexChanged="MotiveDdl_SelectedIndexChanged"></asp:DropDownList>
                        </asp:TableCell>
                    </asp:TableRow>
                    <asp:TableRow>
                        <asp:TableCell>
                                <asp:Label runat="server">Sous-motif : </asp:Label>
                        </asp:TableCell>
                        <asp:TableCell>
                            <asp:DropDownList runat="server" ID="SubmotiveDdl" AutoPostBack="true" OnSelectedIndexChanged="SubmotiveDdl_SelectedIndexChanged"></asp:DropDownList>
                        </asp:TableCell>
                    </asp:TableRow>
                    <asp:TableRow>
                        <asp:TableCell>
                                <asp:Label runat="server">Mots-clés : </asp:Label>
                        </asp:TableCell>
                        <asp:TableCell>
                            <asp:TextBox runat="server" ID="KeywordsTbx" data-target="#modalSuggestions" data-toggle="modal"></asp:TextBox>
                            <div id="keywordsTbxSuggestions"></div>
                            <asp:HiddenField runat="server" ID="KeywordsSearchHfi"></asp:HiddenField>
                        </asp:TableCell>
                    </asp:TableRow>
                </asp:Table>
                <br />
                <asp:Button runat="server" ID="ResearchBtn" Text="Rechercher" OnClick="ResearchBtn_Click" />
                <asp:Button runat="server" ID="ReinitializeBtn" Text="Réinitialiser" OnClick="ReinitializeBtn_Click" />
            </asp:Panel>
        </asp:Panel>
        <br />
        <asp:UpdatePanel runat="server" ID="ResultsUpnl" ChildrenAsTriggers="true" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:Panel runat="server" CssClass="panel-primary">
                    <asp:Panel runat="server" CssClass="panel-heading">Résultat de la recherche </asp:Panel>
                    <asp:Panel runat="server" CssClass="panel-body">
                        <asp:Label runat="server" ID="ResultsLb" Text="Veuillez sélectionner les critères de recherche, puis cliquer sur Rechercher."></asp:Label>
                        <asp:Repeater runat="server" ID="ResultsRpt">
                            <HeaderTemplate>
                                <asp:Label runat="server" Text="<b>Type de demande</b>"></asp:Label>
                                <table>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:Panel runat="server">
                                    <asp:HyperLink runat="server" NavigateUrl='<%# Eval("Link") %>' Text='<%# Eval("Title") %>' Target="_blank"></asp:HyperLink>
                                </asp:Panel>
                            </ItemTemplate>
                            <FooterTemplate>
                                </table>
                            </FooterTemplate>
                        </asp:Repeater>
                    </asp:Panel>
                </asp:Panel>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="ResearchBtn" EventName="Click" />
                <asp:AsyncPostBackTrigger ControlID="ReinitializeBtn" EventName="Click" />
            </Triggers>
        </asp:UpdatePanel>
        <asp:UpdateProgress ID="UppDemandsResult" runat="server" DisplayAfter="0">
            <ProgressTemplate>
                <div style="text-align: center;">
                    <table style="width: 100%;">
                        <tr>
                            <td>
                                <Loader:LoaderComponent ID="UcLoadingProgess" runat="server" />
                            </td>
                        </tr>
                    </table>
                </div>
            </ProgressTemplate>
        </asp:UpdateProgress>
    </form>
</body>

代码隐藏:

private void HandleReinitialization()
{
    this.ResultsLb.Text = DemandCreationConstants.ResearchDefaultText;
    this.familyDdlSelectedValue = string.Empty;
    this.motiveDdlSelectedValue = string.Empty;
    this.submotiveDdlSelectedValue = string.Empty;
    this.LoadFamilies(true);
    this.LoadMotives(false);
    this.LoadSubmotives(false);
    this.ResultsRpt.DataSource = null;
    this.ResultsRpt.DataBind();
    this.KeywordsSearchHfi.Value = string.Empty;
    this.KeywordsTbx.Text = string.Empty;
    LogServiceInstance.Debug("L'utilisateur " + UserSession.UserLogOn + " a réinitialisé la recherche.");
}

HandleReinitialization 由 ReinitializeBtn_Click 事件启动

【问题讨论】:

  • UpdatePanel 仅用于刷新 UpdatePanel 中的内容。您要么需要将所有要更新的内容放入 UpdatePanel 中,要么更好的是,根本不要使用 UpdatePanel,因为它们太糟糕了。而是使用XMLHttprequestWebSockets 等技术在页面加载后与服务器进行交互。
  • 感谢您的建议。由于某些原因,在这种情况下我必须使用 UpdatePanel。我完全同意你的看法,UpdatePanel 是一个非常复杂的控件。

标签: c# asp.net updatepanel updateprogress


【解决方案1】:

如果理解正确,您将需要创建 UpdatePanel2 并向其中添加任何控件,然后在第一个 UpdatePanel1 的按钮 Click() 方法中调用 Update() 方法。

UpdatePanel2.Update();

更新: 确保将 UpdatePanel2 的 UpdateMode 设置为“Conditional”

    <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            // Your controls
        </ContentTemplate>
    </asp:UpdatePanel>

【讨论】:

  • 感谢您的回复,它帮助我处理了这个问题。实际上,您的解决方案还需要在 UpdatePanel 标签中添加“UpdateMode='Conditionnal'”。
  • 不客气,是的,您需要 Conditional,就像在 UpdatePanel1 中一样。我以为你已经知道了 :) 我修改了我的答案。
猜你喜欢
  • 1970-01-01
  • 2017-12-01
  • 1970-01-01
  • 2017-03-04
  • 2013-01-09
  • 2021-12-27
  • 2012-03-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多