在 UpdateProgress 期间隐藏 UpdatePanel

发布于 2024-08-26 13:27:42 字数 507 浏览 4 评论 0原文

我正在寻找在等待提交响应返回时隐藏 UpdatePanel 的最简单方法。 像这里描述的那样 - 使用 Ajax Control Toolkit 和 UpdatePanelAnimationExtender 既矫枉过正,又会导致一些问题,即:

  • 因为页面中有几个隐藏的面板,所以它会变得混乱并隐藏错误的面板。我不知道为什么会发生这种情况;
  • 我找不到一种方法来指定只有一个按钮应该触发动画。我确实在 UpdatePanel 中指定了 a,但似乎被忽略了,面板内的所有控件都会触发动画。

一个简单的 JavaScript 解决方案将是理想的。这里的问题是 ASP.NET 喜欢在运行时为控件生成奇怪的 ID。有什么解决办法吗?

提前致谢。

I'm looking for the easiest possible way to hide an UpdatePanel while waiting for the submit response to come back.
Stuff like described here - using Ajax Control Toolkit and the UpdatePanelAnimationExtender is both overkill and causing some issues, namely:

  • Because there are a couple of hidden panels in the page it gets all messed up and hides the wrong panels. I have no idea why this is happening;
  • I can't find a way to specify that only one button is supposed to trigger the animation. I did specify a in the UpdatePanel, but it seems that is ignored and all the controls inside the panel trigger the animation.

A simple javascript solution would be ideal. The problem here is ASP.NET likes to generate weird IDs for the controls at runtime. Any solutions for that?

Thanks in advance.

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

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

发布评论

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

评论(3

神爱温柔 2024-09-02 13:27:42

处理 PageRequestManager beginRequestendRequest 事件以控制 UpdatePanel 在回发期间的可见性:

    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_beginRequest(
        function (sender, args) {
            $get("<%=someUpdatePanel.ClientID %>").style.display = "none";
        }
    );
    prm.add_endRequest(
        function (sender, args) {
            $get("<%=someUpdatePanel.ClientID %>").style.display = "";
        }
    );

同时将 DisplayAfter="0" 添加到关联的 UpdateProgress 控件,以防止 UpdatePanel 隐藏和 UpdateProgress 显示之间的延迟

Handle PageRequestManager beginRequest and endRequest events to control UpdatePanel's visibility during postbacks:

    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_beginRequest(
        function (sender, args) {
            $get("<%=someUpdatePanel.ClientID %>").style.display = "none";
        }
    );
    prm.add_endRequest(
        function (sender, args) {
            $get("<%=someUpdatePanel.ClientID %>").style.display = "";
        }
    );

Also add DisplayAfter="0" to assotiated UpdateProgress control to prevent delay between UpdatePanel hiding and UpdateProgress showing

与往事干杯 2024-09-02 13:27:42

我建议使用 jQuery。这会让你的事情变得更容易。因此,为了解决“奇怪的 ID”问题,您可以像这样执行一些 jQuery:

$('#<%= someASPControl.ClientID %>').hide();

并显示:

$('#<%= someASPControl.ClientID %>').show();

这是使用 jQuery 通过 id 获取元素,然后您可以用它做您想做的事情。诀窍是“.ClientID”将获取.net 发出的 ID。

I would suggest using jQuery. It will make things easier for you. So to get around the "weird ID" issue you could do some jQuery like this:

$('#<%= someASPControl.ClientID %>').hide();

and to show:

$('#<%= someASPControl.ClientID %>').show();

This is using jQuery to grab a element by id and then you can do what you want with it. The trick is the ".ClientID" that will grab the id that .net sends out.

箜明 2024-09-02 13:27:42

您可以在 html 页面中使用代码标签,并使用控件的 ClientId 属性来吐出 asp.net 生成的 id:

$('#<%= elementName.ClientID %>').hide();

编辑:此示例使用 jQuery btw

You can uses code tags in your html page and use the ClientId property of a control to spit out the id asp.net generates:

$('#<%= elementName.ClientID %>').hide();

EDIT: This example uses jQuery btw

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