How to check whether UpdatePanel is posting back?

[亡魂溺海] 提交于 2019-11-30 19:26:42

I don't know if this will work any better than your solution, but have you tried?:

if (ScriptManager.GetCurrent(Page).IsInAsyncPostBack)
{
    Control ctrl = GetControlThatCausedPostBack(Page);
    if (ctrl is UpdatePanel)
    {
        //handle updatepanel postback
    }
}

private Control GetControlThatCausedPostBack(Page page)
{
    //initialize a control and set it to null
    Control ctrl = null;

    //get the event target name and find the control
    string ctrlName = Page.Request.Params.Get("__EVENTTARGET");
    if (!String.IsNullOrEmpty(ctrlName))
        ctrl = page.FindControl(ctrlName);

    //return the control to the calling method
    return ctrl;
}
kay.herzam

You can check whether the postback was asynchronous and whether it was issued by an update panel looking at these properties:

ScriptManager.GetCurrent(Page).IsInAsyncPostback
ScriptManager.GetCurrent(Page).AsyncPostbackSourceElementID

Try out following:

var controlName = Page.Request.Params.Get("__EVENTTARGET");
if (!String.IsNullOrEmpty(controlName))
{
     // Use FindControl(controlName) to see whether 
     // control is of UpdatePanel type
}

Helpful links:

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