views:

90

answers:

4

We are currently trying to optimize the performance of an ASP.NET based website which has been in development for quite a long time. We are using MS Ajax with UpdatePanels and such. ComponentArt is also part of the picture.

The page load method is very heavy and we are trying to trim some fat from here. Is there any way we can avoid calling page load during a partial postback by a control within an update panel. Is this possible at all without hampering other functionality on the page?

The thread closest to what we are trying to achieve is http://stackoverflow.com/questions/1099330/c-updatepanel-with-timer-pageload. But we don't want to check the event target explicitly because there are dozens of them.

A: 

The page load method is called with every post back including the first time the page is loaded.

You can use the IsPostBack property to determine if it is the first time page loading or the second time. Put all the logic you only want to run once in an if statement.

For example

if (!IsPostBack)
{
   // Do stuff on the first page load only
}
David Basarab
A: 

Sorry, every request to the server (AJAX or otherwise) triggers the full page lifecycle - you need to find a good way of determining if you are dealing with an AJAX request or a full page postback.

http://forums.asp.net/p/1089247/1629084.aspx#1629084 looks like it might help you, so for example you would want something like this:

protected void Page_Load(object sender, EventArgs e)
{
    if(!ScriptManager.GetCurrent(this).IsInAsyncPostBack)
    {
        // This is a normal (i.e. full) postback
    }
}
Kragen
A: 

You can check if partial rendering is being requested by using

void Page_Load(object sender, EventArgs e)
{
    if (!ScriptManager.GetCurrent(this).IsInAsyncPostBack)
    {
        // Do stuff only needed for full rendering here
    }
}
Thorarin
A: 

Somehow I missed responding to the replies here. Thanks a lot for the input guys!

"IsInAsyncPostBack" is what I needed. But after analyzing the project thoroughly, I concluded that it was too convoluted to be optimized in this fashion since it was not originally designed to function that way. Have submitted my proposal to chuck the existing frontend codebase and switch to either Silverlight or Flex.

Thanks again and sorry for the delay in replying.

atlantis