473,569 Members | 2,542 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to dynamically change master page?

ad
Hi,
How can I dynamically change the MasterPager of a web page?
Jun 17 '06 #1
9 16263
"ad" <fl****@wfes.tc c.edu.tw> wrote in message
news:O9******** ********@TK2MSF TNGP02.phx.gbl. ..
How can I dynamically change the MasterPager of a web page?


private void Page_PreInit(ob ject sender, EventArgs e)
{
this.MasterPage File = "MyNewPasterPag e.master" // amend as
appropriate
}
Jun 17 '06 #2
The MasterPage does not support the Page_PreInit so it has to be used in
each content page or a base class must be used which all content pages
inherit from.

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee. com
URL http://www.metromilwaukee.com/clintongallagher/

"Mark Rae" <ma**@markN-O-S-P-A-M.co.uk> wrote in message
news:OG******** ******@TK2MSFTN GP04.phx.gbl...
"ad" <fl****@wfes.tc c.edu.tw> wrote in message
news:O9******** ********@TK2MSF TNGP02.phx.gbl. ..
How can I dynamically change the MasterPager of a web page?


private void Page_PreInit(ob ject sender, EventArgs e)
{
this.MasterPage File = "MyNewPasterPag e.master" // amend as
appropriate
}

Jun 18 '06 #3
"clintonG" <cs*********@RE MOVETHISTEXTmet romilwaukee.com > wrote in message
news:O4******** ******@TK2MSFTN GP03.phx.gbl...
The MasterPage does not support the Page_PreInit
I didn't say it did...
so it has to be used in each content page or a base class must be used
which all content pages inherit from.


Correct.
Jun 18 '06 #4
ad
Thanks,
But if I wish when an user press a button on web page, it will do the change
of mastPage.
How can I do that?
"Mark Rae" <ma**@markN-O-S-P-A-M.co.uk> ¼¶¼g©ó¶l¥ó·s»D: OG************* *@TK2MSFTNGP04. phx.gbl...
"ad" <fl****@wfes.tc c.edu.tw> wrote in message
news:O9******** ********@TK2MSF TNGP02.phx.gbl. ..
How can I dynamically change the MasterPager of a web page?


private void Page_PreInit(ob ject sender, EventArgs e)
{
this.MasterPage File = "MyNewPasterPag e.master" // amend as
appropriate
}

Jun 19 '06 #5
"ad" <fl****@wfes.tc c.edu.tw> wrote in message
news:Oq******** ******@TK2MSFTN GP05.phx.gbl...
Thanks,
But if I wish when an user press a button on web page, it will do the
change of mastPage.
How can I do that?


Do you want the selected MasterPage to be for the whole site (for the
current user), or just for the current page?
Jun 19 '06 #6
ad
For just one page, and change it for a while.
"Mark Rae" <ma**@markN-O-S-P-A-M.co.uk> ¼¶¼g©ó¶l¥ó·s»D: %2************* ***@TK2MSFTNGP0 5.phx.gbl...
"ad" <fl****@wfes.tc c.edu.tw> wrote in message
news:Oq******** ******@TK2MSFTN GP05.phx.gbl...
Thanks,
But if I wish when an user press a button on web page, it will do the
change of mastPage.
How can I do that?


Do you want the selected MasterPage to be for the whole site (for the
current user), or just for the current page?

Jun 19 '06 #7
"ad" <fl****@wfes.tc c.edu.tw> wrote in message
news:e6******** ******@TK2MSFTN GP05.phx.gbl...
For just one page, and change it for a while.


OK, then.

The *only* place that a content page can set its MasterPage is in its
Page_PreInit method, so you're going to have to do the following:

For each content page for which you want to enable dynamic MasterPages,
you'll need to set up a Session variable, which you'll need to initialise on
the Session_Start method in global.asax.

1) E.g. let's say you have a page called MyPage.aspx - in Session_Start,
you'll need to do the following:

Session["MyPage_Mas ter"] = "~/master/Master1.master" ;

2) In the Page_PreInit of MyPage.aspx, you'll need to do the following:

private void Page_PreInit(ob ject sender, EventArgs e)
{
this.MasterPage File = Session["MyPage_Mas ter"].ToString();
}

3) To change the MasterPage, you'll simply need to create an <asp:Button> or
any other webcontrol which can cause a postback, set the
Session["MyPage_Mas ter"] session variable to the new MasterPage, then
Response.Redire ct the page back to itself.

Thereafter, whenever MyPage.aspx is called, it will set its MasterPage to
whatever value is in the Session["MyPage_Mas ter"] session variable.

Sounds a bit convoluted, but it's fairly straightforward once you get your
head round it... :-) Good luck!
Jun 19 '06 #8
ad
Thanks,
Your answer is great, but I have a question about your answer.
Why we need to Response.Redire ct the page back to itself after change the
Session variable of MasgerPage.
I have test if it didn't Response.Redire ct the page back to itself, just
let the page postback, the MasterPage will not change at the fist postback,
I must postbak twice to make the change.

Why?


"Mark Rae" <ma**@markN-O-S-P-A-M.co.uk> ¼¶¼g©ó¶l¥ó·s»D: uT************* ***@TK2MSFTNGP0 4.phx.gbl...
"ad" <fl****@wfes.tc c.edu.tw> wrote in message
news:e6******** ******@TK2MSFTN GP05.phx.gbl...
For just one page, and change it for a while.


OK, then.

The *only* place that a content page can set its MasterPage is in its
Page_PreInit method, so you're going to have to do the following:

For each content page for which you want to enable dynamic MasterPages,
you'll need to set up a Session variable, which you'll need to initialise
on the Session_Start method in global.asax.

1) E.g. let's say you have a page called MyPage.aspx - in Session_Start,
you'll need to do the following:

Session["MyPage_Mas ter"] = "~/master/Master1.master" ;

2) In the Page_PreInit of MyPage.aspx, you'll need to do the following:

private void Page_PreInit(ob ject sender, EventArgs e)
{
this.MasterPage File = Session["MyPage_Mas ter"].ToString();
}

3) To change the MasterPage, you'll simply need to create an <asp:Button>
or any other webcontrol which can cause a postback, set the
Session["MyPage_Mas ter"] session variable to the new MasterPage, then
Response.Redire ct the page back to itself.

Thereafter, whenever MyPage.aspx is called, it will set its MasterPage to
whatever value is in the Session["MyPage_Mas ter"] session variable.

Sounds a bit convoluted, but it's fairly straightforward once you get your
head round it... :-) Good luck!

Jun 20 '06 #9
"ad" <fl****@wfes.tc c.edu.tw> wrote in message
news:uh******** ******@TK2MSFTN GP05.phx.gbl...
Your answer is great, but I have a question about your answer.
Why we need to Response.Redire ct the page back to itself after change the
Session variable of MasgerPage.
I have test if it didn't Response.Redire ct the page back to itself, just
let the page postback, the MasterPage will not change at the fist
postback, I must postbak twice to make the change.

Why?


Because the MasterPage can *only* be set in a content page's Page_PreInit
method.
Jun 20 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5150
by: Rob Roberts | last post by:
In a VS2005 ASP.NET project, I'm trying to find a way to change which css file is linked in based on the browser type. I'd like to use one css file for IE browsers, and a different one for all other browsers. I'm using a MasterPage. I added a Literal control to the Head section of the MasterPage, and then in the Page_Load event I set its...
3
6186
by: Ron | last post by:
Hi all, I've come across a problem when casting user controls in ASP.NET 2.0, hopefully someone can help. I have a master page with a user control on it (myMenu) that I wish to programmatically access from a content page. Below is how I am trying to do this (this would work in ASP.NET 1.1). DynamicMenu myMenu =...
2
1448
by: Mark Rae | last post by:
Hi, It's easy enough to get a content page to refer to public properties on its associated master page e.g. public partial class master_secure : System.Web.UI.MasterPage { public Label MyLabel = new Label(); }
4
3131
by: David Lozzi | last post by:
Howdy, I have my master page, and I would like to change the background CSS class per the content page. Only the home page has a different background style, all other pages are using the same. I know I can create a new master page, but I'd like to just change the master page from the content page if possible. thanks!
12
4904
by: Mark Rae | last post by:
Hi, It's easy enough for a child page to manipulate its MasterPage's header simply by modifying the MasterPage thus: <header runat="server"> .... .... </header>
23
12518
by: LvBohemian | last post by:
I am playing around with creating some menus dynamically, and they create fine and show up ok when I want them to; but when I select a menu NavigateUrl at run time, the applicable url shows up as anticipated in the content place holder but the menu disappears... the menu is part of the master page and is not in the
1
1382
by: Dinu | last post by:
How to Dynamically program User controls in a Master page from a content page Thanks
4
5654
by: CJM | last post by:
I have a site that is being built using master pages, and includes a menu that I want to manipulate dynamically. Specifically the currently-selected menu option is styled differently to the others, as follows: <div id="menu"> <ul> <li class="current_page_item"><a href="/">Home</a></li> <li><a href="/about/">About Us</a></li>
6
2543
by: _Who | last post by:
I use the code below to change to a style sheet that has: body { ....
0
7700
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8125
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.