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. |
No comments:
Post a Comment