开发者

asp.net prevent events from being raised

开发者 https://www.devze.com 2022-12-17 06:11 出处:网络
I have a control (.ascx) that sits on a page (.aspx). Within that control there\'s a asp.net update panel that encompasses everything for that control. When the control does a post back it automatical

I have a control (.ascx) that sits on a page (.aspx). Within that control there's a asp.net update panel that encompasses everything for that control. When the control does a post back it automatically raises all the events from the control plus all the events from the page it sits on. This is causing significant performance problems.

Is there any wa开发者_如何学Goy to stop the events from being raised that reside on the page that the control is sitting on?

Thanks


Check the ScriptManager.IsInAsyncPostBack Property.

Here is the sample code:

protected void Page_Load(object sender, EventArgs e)
{
    if (Page.IsPostBack)
    {
        // get a reference to ScriptManager and check if we are in a partial postback
        if (ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack)
        {
            // partial (asynchronous) postback occured
            // insert Ajax custom logic here
        }
        else
        {
            // regular full page postback occured
            // custom logic accordingly                
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消