Senator Guerra Souty original series calendar,replica hublot blue steel peach pointer collocation of rolex replica Rome digital scale, track type minute replica watches scale shows that the classical model is swiss replica watches incomparable, wearing elegant dress highlights.
mr-ponna.com

 

YOU ARE HERE: HOME Questions Can we set Master page dynamically at runtime



Change the Master Pages Dynamically

View(s): 27880

Can we set Master page dynamically at runtime?

Answer 1)


Yes
. Set the MasterPageFile property only during the PreInit page event—that is, before the runtime begins working on the request (since the rendering of the page with the master page occurs prior to the Init event)

protected void Page_PreInit(object sender, EventArgs e)
{
       MasterPageFile = "simple2.master";
}

If you try to set the MasterPageFile property in Init or Load event handlers, an exception is raised.

Note:  The Master property represents the current instance of the master page object, is a read-only property, and can't be set programmatically. The Master property is set by the runtime after loading the content of the file referenced by the MasterPageFile property.

                The above code needs to add in every page of the site. Instead, it is easy enough to add that code to a base page class that you can inherit from for you pages in the site.  In case if you do not already have the base page, you can use the following web.config settings to have a base class without having to modify the existing aspx pages.

<system.web>
  <!-- ... -->
  <pages pageBaseType="MyWeb.UI.MyPageBase" />
  <!-- ... -->
</system.web>

  Asked in:  TCS (Tata Consultancy Services)   Expertise Level:  Intermediate
  Last updated on Saturday, 05 January 2013
5/5 stars (15 vote(s))

Register Login Ask Us Write to Us Help