Click here to Skip to main content
15,066,634 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
How to bind a master page dynamically to a web page?
Posted
Comments
pankajupadhyay29 24-Mar-11 0:17am
   
not clear what you mean by binding master page

To add master Page dynamically you should use Page_PreInit event of content page. So at Page_PreInit you have to access Master Page name since this Page_PreInit event occurs before Load event you can use Request.QueryString, cookies etc to access the name of Master Page.
Like in following example I use Request.QueryString to access the name of Master Page.
Since you can have more than 1 Master page, add name of all Master Page to a DropDownList
Use following at default.aspx at any event.
Server.Transfer("Default2.aspx?val="+DropDownList1.SelectedValue+"");


But before these you have to create Master Pages named those properly.

Default2 page should look like follow

C#
void Page_PreInit(object sender,EventArgs e)
    {
                   string str= (string)Request.QueryString["val"];
                   this.MasterPageFile = str;
    }
   
v3
Comments
Thatikonda Ragamaie 4-Apr-11 1:08am
   
Thank you so much Brijesh..
[no name] 5-Apr-11 5:07am
   
You're Most Welcome
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900