Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is application in asp net?

858


What is asp net theme?

952


Explain some of the major built-in objects in asp.net

998


Explain the difference between Web Garden and Web Farm?

945


Can we use MSSql as backend in asp.net...if yes then How.?

993


Why is mvc better than asp.net?

996


Define secured sockets layer.

897


What happens if an ASP.NET server control with event-handling routines is missing from its definition?

1066


Explain about the Class view window?

930


How do you implement sql caching in asp.net?

1001


i have 3+ exp in .net? i am going interview now but they asked me do you know any TOOL? which tool will i study please refer me?

2288


What is the biggest disadvantage of “Other Return Types” in Web API?

1370


How do active server pages work?

931


How can i explain my project during interview?many time i expalain my project but they did't accept? please explain me.

5503


Where do we store our connection string in asp.net application?

964