ASP.NET AJAX UpdateProgress in User Control for UpdatePanel in parent page

这一生的挚爱 提交于 2019-12-11 07:37:42

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/3193550/asp-net-ajax-updateprogress-in-user-control-for-updatepanel-in-parent-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!