简体   繁体   中英

Optimizing performance of an ASP.NET website

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 c# updatepanel with timer page_load . But we don't want to check the event target explicitly because there are dozens of them.

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
    }
}

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
}

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
    }
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM