Difference between Master Page and UserControl

 Posted by Ddd on 2/9/2011 | Category: ASP.NET Interview questions | Views: 10995 | Points: 40

Master Page and User Control are both used to provide a common design which can then be used in .aspx pages. We can pass data from Master Page or UserControl to .aspx pages and viceversa.

MasterPages and UserControl both cannot be accessed directly.

Master pages

1)Files with .Master extension. Introduced in ASP.NET 2.0.

code file: .master.cs or .master.vb extension

can use all toolbox controls.

2)These have a control known as the ContentPlaceHolder which reserves a storage location in which we can place the contents of a .aspx page.
The common part for the .aspx pages will be outside the ContentPlaceHolder

2 ContentPlaceHolders are by default , but we can increase or decrease the ContentPlaceholders as per our needs.

A referencing control of ContentPlaceHolder known as Content will be placed in .aspx page that uses the Master Page.

3)MasterPageFile attribute is added in the Page directive of the .aspx page when a Master Page is referenced in .aspx page. The .aspx page that uses the Master page i known as Content Page.

4)Can be referenced using Web.Config file also or dynamically by writing code in PreInit event.

5)More suitable for large designs(ex: defining the complete layout of .aspx page)

User Control

1)Files with .ascx extension.

Code file: .ascx.cs or .ascx.vb

can use all toolbox controls.

2)These do not have any ContentPlaceHolder control which makes it somewhat difficult in providing proper layout and alignment for large designs.

3)Register Tag is added when we drag and drop a user control onto the .aspx page.

4)Can be attached dynamically using LoadControl method.PreInit event is not mandatory in their case for dynamic attachment.

5)Suitable for small designs(Ex:1) logout button on every .aspx page.

2)this type of design:
enter shipper name : TextBox

shipper address: TextBox


UserControls can be used in Master Pages, but Master Pages cannot be used in User Controls.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response