加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 为什么设置AssociatedUpdatePanelId时不会触发Update

发布时间:2020-12-16 07:26:10 所属栏目:asp.Net 来源:网络整理
导读:当我分配AssociatedUpdatePanelId时,我选择状态时不会显示进度,但是当我将其留空时,它会显示进度. 这是aspx标记: div asp:ListBox ID="lstStates" runat="server" AutoPostBack="True" OnSelectedIndexChanged="lstStates_SelectedIndexChanged" SelectionM
当我分配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>

解决方法

根据 this article,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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读