为什么设置 AssociatedUpdatePanelId 后更新进度不会触发?

发布于 2024-07-24 16:33:35 字数 1123 浏览 2 评论 0原文

当我分配 AssociatedUpdatePanelId 时,当我选择状态时不会显示进度,但当我将其留空时,它会显示进度。

这是 aspx 标记:

<div>
    <asp:ListBox ID="lstStates" runat="server" AutoPostBack="True"
    OnSelectedIndexChanged="lstStates_SelectedIndexChanged" SelectionMode="Multiple">
    </asp:ListBox>
</div>
<div>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
    <asp:Panel ID="pnlCounty" runat="server">
    <asp:ListBox ID="lstCounties" runat="server" SelectionMode="Multiple">
    </asp:ListBox>
    </asp:Panel>
    </ContentTemplate>
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="lstStates" EventName="SelectedIndexChanged" />
    </Triggers>
    </asp:UpdatePanel>
    <asp:UpdateProgress ID="UpdateProgress2" runat="server" DisplayAfter="1"
                        AssociatedUpdatePanelID="UpdatePanel1">
    <ProgressTemplate>
    <img src="../images/loader2.gif" />
    Loading Counties...
    </ProgressTemplate>
    </asp:UpdateProgress>
</div>

When I assign the AssociatedUpdatePanelId, the progress does not display when I select a state, but when I leave it blank, it displays the progress.

Here is the aspx markup:

<div>
    <asp:ListBox ID="lstStates" runat="server" AutoPostBack="True"
    OnSelectedIndexChanged="lstStates_SelectedIndexChanged" SelectionMode="Multiple">
    </asp:ListBox>
</div>
<div>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
    <asp:Panel ID="pnlCounty" runat="server">
    <asp:ListBox ID="lstCounties" runat="server" SelectionMode="Multiple">
    </asp:ListBox>
    </asp:Panel>
    </ContentTemplate>
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="lstStates" EventName="SelectedIndexChanged" />
    </Triggers>
    </asp:UpdatePanel>
    <asp:UpdateProgress ID="UpdateProgress2" runat="server" DisplayAfter="1"
                        AssociatedUpdatePanelID="UpdatePanel1">
    <ProgressTemplate>
    <img src="../images/loader2.gif" />
    Loading Counties...
    </ProgressTemplate>
    </asp:UpdateProgress>
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ペ泪落弦音 2024-07-31 16:33:35

根据 本文,UpdatePanel 的外部触发器不会触发关联的 UpdateProgress,由于启用 UpdateProgress 控件的实现会在控件层次结构中搜索调用控件; 外部触发器不会出现在控制层次结构中。

然而,这篇文章确实建议注入一些 JavaScript 来弥补这个错误; 我已经对其进行了修改(希望)满足您的需求:

<script type="text/JavaScript" language="JavaScript">
    function pageLoad()
    {      
       var manager = Sys.WebForms.PageRequestManager.getInstance();
       manager.add_endRequest(endRequest);
       manager.add_beginRequest(OnBeginRequest);
    }
    function OnBeginRequest(sender, args)
    {
      var postBackElement = args.get_postBackElement();
      if (postBackElement.id == 'lstStates')
      { 
     $get('UpdateProgress2').style.display = "block";  
      }
   }
</script>

According to this article, external triggers for an UpdatePanel do not fire an associated UpdateProgress, since the implementation of enabling the UpdateProgress control searches the control hierarchy for the calling control; an external trigger will not be present in the control hierarchy.

The article does, however, suggest injecting some JavaScript to make up for this error; I have modified it to (hopefully) fit your needs:

<script type="text/JavaScript" language="JavaScript">
    function pageLoad()
    {      
       var manager = Sys.WebForms.PageRequestManager.getInstance();
       manager.add_endRequest(endRequest);
       manager.add_beginRequest(OnBeginRequest);
    }
    function OnBeginRequest(sender, args)
    {
      var postBackElement = args.get_postBackElement();
      if (postBackElement.id == 'lstStates')
      { 
     $get('UpdateProgress2').style.display = "block";  
      }
   }
</script>
怂人 2024-07-31 16:33:35

不要忘记

$get('UpdateProgress2').style.display = "block"; 

使用

$get('<%=UpdateProgress2.ClientID%>').style.display = "block";  

.NET 为控制器创建自己的名称(实际上附加“MainContent”或其他名称)。

Don't forget instead of

$get('UpdateProgress2').style.display = "block"; 

to use

$get('<%=UpdateProgress2.ClientID%>').style.display = "block";  

as .NET makes up its own name for the controller (actually appends "MainContent" or whatever to it).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文