为什么设置AssociatedUpdatePanelId时不会触发Update Progress?

Xai*_*oft 4 asp.net updatepanel

当我分配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>
Run Code Online (Sandbox Code Playgroud)

Mat*_*nes 10

根据这篇文章,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>
Run Code Online (Sandbox Code Playgroud)