|
One of the best ways to increase performance in ASP.Net pages is to not do any unnecessary server-side work. For example, every postback and callback will re-trigger the entire Page's server life cycle - rerunning OnInit, OnLoad, OnPreRender, etc... However, a server-side action only require a fraction of the original code to run - for example clicking a button may not require you to repopulate all dropdowns.
| Concept | Example | Details |
| Is Postback | Clicking an ASP.Net button postbacks the page | this.IsPostBack |
| Is Callback | A JavaScript triggers an ASP.Net 2.0 callback | this.IsCallback |
| Is Redirecting | A method has called Response.Redirect, but there is still heavy processing (that is now unnecessary) that will still be called. | Response.IsRequestBeingRedirected |
| Is Ajax update panel postback | A button within an Ajax update panel has been clicked, but don't redo server work outside of that update panel | public static bool IsPartialPostback(System.Web.UI.Page p) { return ((System.Web.UI.ScriptManager.GetCurrent(p) != null) && (System.Web.UI.ScriptManager.GetCurrent(p).IsInAsyncPostBack)) } |
| Is Button click | User clicks exit button - no need to repopulate dropdowns | Request["__EVENTTARGET"] //indicates which event (like a button) triggered the postback. |
You must have been reading my mind, I was researching some of these methods
this morning, especially the IsCallBack and the IsRequestBeingRedirected
the MSDN documentation is not really helpful on these 2 methods, I was
wondering if you might provide a couple samples of when they would be
useful?
Hey Jeff, Good question. I don't have a short, easy-to-reproduce example.
But what I have seen is that in larger frameworks, sometimes the page will
redirect, but then it will still continue doing processing in other methods
further down in the page life cycle (I think I've seen this in the
Page.OnPreRender method). So, I'd use this step for tuning - if you find
your framework still runs a method even after the page has somehow
redirected, consider adding a check to Response.IsRequestBeingRedirected.