父页面中 UpdatePanel 的用户控件中的 ASP.NET AJAX UpdateProgress

发布于 2024-09-08 10:57:51 字数 996 浏览 0 评论 0原文

我正在开发 ASP.NET Web 表单应用程序。在我的页面中,我有一个 UpdatePanel 和一个带有 UpdateProgress 和一堆按钮的用户控件。当用户单击其中一个按钮时,我想执行异步回发并显示 UpdateProgress

任何人都可以帮助我使回发异步(看起来有效)以及使UpdateProgress出现(尚未起作用) ?

通常,通过在页面标记中定义 UpdateTrigger 可以很容易地完成此操作。在用户控件内部它不是。我公开了一个公共属性 AssociatedUpdatePanelID,以便在控件内拥有 UpdatePanel 的 ID。

UpdateProgress 定义如下:

<asp:UpdateProgress AssociatedUpdatePanelID='<%# AssociatedUpdatePanelID %>' />

这就是我在控件的 Page_Load 中尝试的方法,但没有一种方法有效(执行回发,但 UpdateProgress没有出现):

updatePanel.Triggers.Add(new AsyncPostBackTrigger()
{
    ControlID = this.ID,
    EventName = "RequestOptimize"
});

var scriptMgr = ToolkitScriptManager.GetCurrent(Page);
scriptMgr.RegisterAsyncPostBackControl(optimizeButtonJobs);
scriptMgr.RegisterAsyncPostBackControl(this);

I'm working on an ASP.NET web forms application. In my Page I have an UpdatePanel and a user control with an UpdateProgress and a bunch of buttons. When the user clicks one of the buttons, I'd like to perform an asynchronous postback and show the UpdateProgress.

Can anyone help me with making the postback asynchronous (looks like it works) as well as making the UpdateProgress appear (doesn't work yet)?

Usually, this can be done pretty easily by defining an UpdateTrigger in the page markup. Inside the user control it isn't. I exposed a public property AssociatedUpdatePanelID, to have the UpdatePanel's ID inside the control.

The UpdateProgress is defined as follows:

<asp:UpdateProgress AssociatedUpdatePanelID='<%# AssociatedUpdatePanelID %>' />

That's what I tried in my control's Page_Load, but none of the approaches works (postback is performed, but UpdateProgress does not appear):

updatePanel.Triggers.Add(new AsyncPostBackTrigger()
{
    ControlID = this.ID,
    EventName = "RequestOptimize"
});

var scriptMgr = ToolkitScriptManager.GetCurrent(Page);
scriptMgr.RegisterAsyncPostBackControl(optimizeButtonJobs);
scriptMgr.RegisterAsyncPostBackControl(this);

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

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

发布评论

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

评论(1

最近可好 2024-09-15 10:57:51

您只需在页面上将用户控件注册为异步回发触发器即可。不再需要魔法。它对我不起作用的原因是(意外地)在按钮上设置了 PostBackUrl 属性。

<asp:AsyncPostBackTrigger ControlID="myCustomControl" />

You can just register your user control on the page as an async postback trigger. No more magic required. The reason it didn't work for me was a PostBackUrl property that was (accidentially) set on the button.

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