ASP.NET: UpdateProgress与ClientIDMode="Static"的控件不兼容,无法正常工作。

7

看一下这个标记:

<asp:UpdatePanel ID="Panel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:DropDownList ID="cboBox1" ClientIDMode="Static" AutoPostBack="true" runat="server" />
    </ContentTemplate>
</asp:UpdatePanel>

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:DropDownList ID="cboBox2" runat="server" />
        <asp:UpdateProgress ID="UpdateProgress1" style="display: inline" AssociatedUpdatePanelID="Panel1" DynamicLayout="false" DisplayAfter="0" runat="server">
            <ProgressTemplate>
                <img src='<%= ResolveClientUrl("~/Images/indicator.gif")%>' border="0" alt="" />
            </ProgressTemplate>
        </asp:UpdateProgress>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="cboBox1" EventName="SelectedIndexChanged" />
    </Triggers>
</asp:UpdatePanel>

更新进度控件最初是可以工作的,但是当我们向cboBox1添加了ClientMode="Static"后就出现了问题。回滚到AutoID不是一个选项,所以我需要找到解决方案,使UpdateProgress面板能够与ClientIDMode="Static"一起使用。
另外,能否有人将"clientidmode"添加到标签列表中?

请问为什么您必须使用静态客户端模式?您是否在某些JavaScript中使用该控件? - TheGeekYouNeed
为什么“AutoID”模式不是一个选项? - Didier Ghys
是的,我们在JavaScript中使用它,但JavaScript是从另一个文件导入的,所以我们不能使用服务器标记。我们可以将各种JavaScript函数移动到主页面,但这是我们现在不想做的事情。我们从离岸开发团队继承了这个编写不良的应用程序,它与最佳实践不兼容,因此我们正在尽力而为,直到重写它的时候。还有更多内容,所以你只能相信我。 - oscilatingcretin
1
你的项目中使用jQuery吗?(这只是一个问题,我并不是在告诉你应该使用它...)如果是这样,你可以使用属性选择器来选择使用ClientIDMode="AutoID"创建的元素:$('select[id$=cboBox2]')(id以"cboBox2"结尾)。 - Didier Ghys
我们使用jQuery。如果我得到了对cboBox2的引用,我最终会用它做什么? - oscilatingcretin
oscilatingcretin -- 你将像静态名称一样对其进行相同的操作。 - TheGeekYouNeed
1个回答

2

看起来这是PageRequestManager中的一个bug,因为postBackElement没有传递到beginRequest事件处理程序。对于这个特定的问题,您可以使用以下脚本:

$(function () {
     $("#cboBox1").live("change", function () {
          window.setTimeout(function () {
               var progress = $find("<%= UpdateProgress1.ClientID %>");
               // since you use 0 DisplayAfter property value you may 
               // just call progress.set_visible(true);
               // without timeout usage
               window.setTimeout(function () { progress.set_visible(true); }, progress.get_displayAfter());
          }, 0);
     });
});

不错!奏效了。这是个取巧的方法,但我现在要继续使用它。 - oscilatingcretin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接