How can you change a Master page dynamically in which event
of page life cycle?

Answers were Sorted based on User's Feedback



How can you change a Master page dynamically in which event of page life cycle?..

Answer / ss

In Page_PreInit(object sender, EventArgs e) Event ...

Is This Answer Correct ?    14 Yes 4 No

How can you change a Master page dynamically in which event of page life cycle?..

Answer / ashutosh tripathi

Unfortunately there is not built in support to change page
themes at runtime. Here is a simple code which can be used
to change page themes at runtime:
At first though we may say we can easily achieve this by
coding it in Page_Preinit Event as shown below.

protected void Page_PreInit(object sender, EventArgs e)
{
Page.Theme = "Black"

}

But problem with this is we cant assign value from dropdown
box because Page_Preinit event is fired much before
dropdown has changed value.

To resolve this issue, just use the following steps:
1-Create one session variable which will hold current theme
value
2-On selection change event of dropdown combo box , assign
value form combo box to session variable.
3-During Page_preInit Event assign this variable value to
Page.Theme property.
4-Stop page loading and reload same page again using
server.transfer method as shown below


protected void Page_PreInit(object sender, EventArgs e)
{
string thm;
thm = (string)Session["themeSelected"];
if (thm != null)
{
Page.Theme = thm;
DropDownList1.Text = thm;
}
else
{
Session["themeSelected"] = DropDownList1.Text;
Page.Theme = "Blue";
}

protected void DropDownList1_SelectedIndexChanged(object
sender, EventArgs e)
{
Session["themeSelected"] = DropDownList1.Text;
Server.Transfer(Request.FilePath);

}


Is This Answer Correct ?    8 Yes 1 No

Post New Answer

More ASP.NET Interview Questions

What is the purpose of using MVC programming pattern in ASP.NET?

0 Answers   PUCIT,


Can the dictionary object be created in client?s scope ?

0 Answers   Satyam,


If we write return statement in finally block will it works fine or throws any error?

1 Answers   Patni,


Explain how asp.net different from asp?

0 Answers  


Explain model, view and controller represent in an mvc application? : asp.net mvc

0 Answers  


Explain the difference between codebehind="mycode.aspx.cs" and src="mycode.aspx.cs"?

0 Answers  


how we use web services

2 Answers  


What property must you set, and what method must you call in your code, in order to bind the data from a data source to the Repeater control?

1 Answers   Siebel,


How to prepare culture-specific formatting in .net.

0 Answers  


WHT IS DIFFERENCES BETWEEN HTML CONTROLS AND SERVER CONTROLS.

11 Answers   HCL, Microsoft,


What is the difference between debug and release?

0 Answers  


When Garbage Collector runs in an Application? 1)Application is running form more than 30 min. 2)On every 1/4th milisecond 3) Randomly 4) Application is running on low of memory

2 Answers   PCS,


Categories