Reader Level:

Load Master Page User Control Dynamically to Improve Performance

By Venkatesh Kumar on Aug 03, 2012
In this article, we will see how to load an ASP.NET user control dynamically to improve performance. We will start with a problem-solution approach.


Problem: We have the master page and we will embed the user the control and the same master page will used by various pages. For some pages we don't require the user control to be visible. If we also hide the call to that user control, we cannot avoid it.

Step 1 : We have very simple user control, just some label in HTML.


Step 2 : In code behind, we will hold the thread for a while, assuming we are doing some complex process in that user control and display the content.


Step 3 : Add the user control to the master page. First register it and using the tag name embed the control.


Step 4 : Just create a new ASP.Net page with master page reference and load it and the result will be as below. Ignore the design aspects; we will focus on the user control alone.


The User Control will be loaded in right side and below the load time as well.

Step 5 : We will create one more page, that doesn't require the user control. We will just hide the control using jQuery.

Even if we hide also, the user control will be called internally.


Step 6 : We will remove the user control related "HTML" in the master page and just add a placeholder.


Step 7 : Now we can load the master page control from the child/content page. Write the following code in the Page_LoadComplete event of the Content Page, which comes just after the Page_Load event of the Master Page.

We will run the page and get the same result as below.


Now we will load the other page which doesn't require the Master Page User Control. It just loads the master and child page contents alone.



We need to add some code in the page which requires loading the Master Page User Control dynamically.

Venkatesh Kumar
Venkatesh Kumar

Interested in learning Microsoft Technologies and following my Mentors/Virtual Experts.



Spire.Doc - Free .NET Word API
Use Spire.Doc to create, read, write, print, and convert word documents to OpenXML, RTF, TXT, XPS, EPUB, EMF, HTML, Image and PDF.

Trending up