Click here to Skip to main content
15,867,308 members
Articles / Web Development / ASP.NET

How to Improve ASP.NET UpdatePanel Performance

Rate me:
Please Sign up or sign in to vote.
4.75/5 (7 votes)
29 Dec 2010CPOL3 min read 44.4K   16   5
How to Improve ASP.NET UpdatePanel Performance

Since ASP.NET AJAX UpdatePanel was first introduced, it has earned a strange mix of reputation. On the one hand, it has become a tool of first choice for many ASP.NET developers who wanted an easy way of introducing an AJAX-like behavior for their ASP.NET web apps. On the other hand, it has earned a lot of criticism from seasoned web developers because of certain performance consequences associated with complex usage scenarios.

Well, everything may be good and may be evil based on how we use it. From my experience, conscious and judicious use of UpdatePanel is the key to saving its benefits and avoiding potential problems.

Below, I suggest a number of rules that help achieving better results when using UpdatePanel.

  • Avoid automatic refreshing of UpdatePanel; always stay in control of which UpdatePanel and when refreshes: set UpdateMode property to Conditional (the default value is Always).
  • Minimize the content of the UpdatePanel: the <ContentTemplate> should only include controls that are necessary to refresh. For instance, if user input requires server-side validation, include only an error message mark-up in the UpdatePanel and leave the rest of the form outside.
  • Try to keep the partial postback trigger controls outside of their respective UpdatePanels unless its necessary to change their markup.
  • Try to stick to a simple rule: one trigger for one UpdatePanel. If you need to refresh multiple UpdatePanels during one request, add a trigger control to only one of those UpdatePanels and refresh the others programmatically in an event handler on the server. The idea is to avoid uncontrollable refreshing of unnecessary UpdatePanels.
  • Since ViewState is updated with every partial postback request, turn the ViewState off on a page that contains the UpdatePanel wherever possible or store the ViewState on the server to avoid transferring it back and forth with every async request.
  • Since Page runs through its lifecycle during every partial postback and executes methods like Page_Load or Page_PreRender, make sure that logic that is unnecessary for refreshing UpdatePanel is not executed by wrapping it in if(!ScriptManager.IsInAsyncPostBack).
  • If you use UpdatePanel event handlers like Init, Load, PreRender and Unload, make sure that code inside these event handlers does not execute unless necessary by checking Page.IsPostBack and ScriptManager.IsInAsyncPostBack properties.
  • If you trigger an UpdatePanel programmatically from the client-side (via JavaScript), make sure that its event handler check for the event trigger value using Request.Params["__EVENTTARGET"] to avoid unnecessary execution path.
  • If you programmatically update Page's Header (Title, etc.) or other Page's content that is outside UpdatePanel, make sure that this code never gets executed during partial postbacks. First of all, it's not necessary since page does not refresh but also it may be dangerous because the content may not be handled properly by a browser.

Conclusion

There may probably be more tricks and tips regarding usage of UpdatePanel, but those mentioned above have been proven by real experience. I would also recommend reading an excellent post by Dave Ward that helps in understanding how UpdatePanel works behind the scenes and never hesitate using Fiddler to investigate what your web app's doing.

This article was originally posted at http://feeds.feedburner.com/Webnet

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Canada Canada
Alexander Turlov is a professional software development consultant that has been working in IT industry since 1987. His programming experience includes such languages as FORTRAN, Pascal, Basic, C, C++ and C#. He's been working for different industries including but not limited to science, manufacturing, retail, utilities, finance, insurance, health care, education and so on. His area of professional interests is cloud powered rich web applications development with .NET, C#, ASP.NET/MVC and JavaScript. He is working in software development doing architecture, design and development on .NET platform and using Microsoft Visual Studio, Azure and Visual Studio Team Services as his primary tools. He holds a M.Sc. degree in physics and various industry certifications including MCSD.NET, Azure and Scrum.

View my profile on LinkedIn

View my blog

Comments and Discussions

 
Questionvery good article Pin
a_shyam4128-Apr-17 3:24
a_shyam4128-Apr-17 3:24 
GeneralMy vote of 4 Pin
ahsan sarfraz23-Jan-11 23:52
ahsan sarfraz23-Jan-11 23:52 
GeneralMy vote of 4 Pin
lerit_liu5-Jan-11 15:32
lerit_liu5-Jan-11 15:32 
GeneralGood one Pin
thatraja31-Dec-10 0:43
professionalthatraja31-Dec-10 0:43 
Generalthanks for sharing Pin
Pranay Rana29-Dec-10 18:48
professionalPranay Rana29-Dec-10 18:48 
thanks for sharing -- have 5
For any question : http://pranayamr.blogspot.com/

vote my article :

Learn SQL to LINQ ( Visual Representation )


Calling WCF Services using jQuery

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.