【问题标题】:ASP.NET: UpdateProgress doesn't work with controls that have ClientIDMode="Static"ASP.NET:UpdateProgress 不适用于具有 ClientIDMode="Static" 的控件
【发布时间】:2012-01-13 04:39:05
【问题描述】:

看看这个标记:

<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>

UpdateProgress 控件最初可以工作,但是当我们将 ClientMode="Static" 添加到 cboBox1 时就坏了。将其恢复为 AutoID 不是一种选择,因此我需要找到允许 UpdateProgress 面板与 ClientIDMode="Static" 一起使用的解决方案。

另外,有人可以在标签列表中添加“clientidmode”吗?

【问题讨论】:

  • 请问为什么一定要使用静态客户端模式?您是否在某些 javascript 中使用该控件?
  • 为什么不能选择“AutoID”模式?
  • 是的,我们在Javascript中使用它,但是Javascript是从另一个文件导入的,所以我们不能使用服务器标签。我们可以将各种 Javascript 函数移到主页上,但这是我们不想在游戏后期这样做的事情。我们从一个离岸开发团队继承了这个写得很糟糕的应用程序,它不能很好地发挥最佳实践,所以我们现在正在尽我们所能,直到需要从头开始重写它。不仅如此,您只需要相信我。
  • 你在你的项目中使用jquery吗(这只是一个问题,我不是告诉你应该使用它...)?如果是这样,您可以使用属性选择器选择使用 ClientIDMode="AutoID" 创建的元素:$('select[id$=cboBox2]')(id 以 "cboBox2" 结尾)
  • 我们使用jquery。如果我确实得到了对 cboBox2 的引用,我最终会用它做什么?

标签: javascript asp.net static updatepanel updateprogress


【解决方案1】:

看起来这是PageRequestManager 中的一个错误,因为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);
     });
});

【讨论】:

  • 不错的一个!工作。这是一个 hack,但我现在要使用它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-26
  • 2017-11-13
  • 1970-01-01
  • 1970-01-01
  • 2022-09-25
  • 1970-01-01
相关资源
最近更新 更多