Exforsys.com
 
Home Tutorials ASP.NET 2.0
 

ASP.NET 2.0 :Changing Master Pages Dynamically

 

ASP.NET 2.0 :Changing Master Pages Dynamically

Page 1 of 2

ASP.NET 2.0 Free Training : Changing Master Pages Dynamically

In this tutorial you will learn how to make a copy of the master page, To add buttons for selecting an alternate master page, To write code to dynamically select the master page and test the dynamic master pages.


Changing Master Pages Dynamically

Dynamically changing master pages is possible. The code can be used to set the master for the content. This may especially be useful when users want to select from several different layouts to set their preferences. To see how this is done let us add another Master page to our website and allow the user to select the template he wants.


The first step is to make a copy of the Master as we want the second page to approximate to the first Master.


To make a copy of the master page


1. In Solution Explorer, right-click MasterPag.master, and then click Copy.


2. Right-click the name of the Web site, and then click Paste.


3. A master page is added to the Web site with the name Copy of masterPage.master.



4. Right-click Copy of masterPage.master, click Rename, and then name the new master page MasterPage2.master.


5. Open Master2.master and in the @ Master directive, change MasterPage to MasterPage2.


6. Switch to Design view.


7. In the Properties window, in the drop-down list at the top, click DOCUMENT.


8. Set the BgColor property to the color of your choice.


9. The new master page will look and function like MasterPage.master, but will have a different background color




10. Open the master page's code file, and then change the class name from MasterPage_master to MasterPage2_master.


The next step is to add a button to each master page that allows the user to select the alternate master page.


Next Page: ASP.NET 2.0 :Changing Master Pages Dynamically - Page 2





 

 

Comments


Megan McVey said:

  8. Double-click the Master 1 button to create a handler for its Click event, and then add the following highlighted code:

(and there is no code)

I mean, ya, I can figure it out (and want to store in the DB anyway not the session...) but still!!

Megan
March 15, 2007, 11:23 am

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2010 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape