views:

27

answers:

1

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 way to stop the events from being raised that reside on the page that the control is sitting on?

Thanks

+1  A: 

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                
        }
    }
}
Gabriel McAdams
I'm testing this now. Unfortunately I don't have access to the code behind for the page but I'm attempting to override the OnLoad to test this.
Brandon
So far no luck... There's still tons of events being raised on the page.
Brandon
The events will always be raised with postbacks - that is by design. You have to filter them out using the technique above. You may want to look at callbacks for something more efficient (albeit a bit more complicated to implement).
Jason Kealey
Yeah, I'm not sure what we're going to do. I wish there was a simple way to just stop all events for the page from being raised but doesn't sound like there is...
Brandon
@Brandon: There isn't any way to stop all events.
Gabriel McAdams
Look at this page to see a method of updating information without the use of the UpdatePanel. http://msdn.microsoft.com/en-us/magazine/cc163413.aspx#S4
Gabriel McAdams
Please remember to accept this answer if you found it useful.
Gabriel McAdams