Professional Documents
Culture Documents
ASP Master Pages
ASP Master Pages
Give us the ability to create a consistent layout for the entire website.
The extension of the master page is : .master
And cannot be run alone ( cannot create an object form)
A content page must inherit from.
Content Place Holder: is the part of the page we can modify in each
page
Make a new website and in website add new item and select master
page and press ok.
Notice in the html source its <%@ Master not @page
And cut and paste the code from page 3 to class1 outside the
constructor with the same pre init function from page 3
Now its as if the content page have 2 parents
Master page : feed it design
Class 1 : comman functions and code
Another exercise
How to change master page at run time?
We make 2 master pages and put a drop down list to let the user
choose which theme ( thus master page he want)
Now copy the masterpage from solution explorer then right click the
main site node and paste it
Now change the label background and rename it to me colorful
Go to page 3 and put 2 buttons name 1 classic and other colorful
Go to colorful button code
The last event to change the master page is the pre init
And to classic button and code it
( we just put a session with a string colorful or classic)
Now go to class 1 in the pre init event and ask for the session
See the if other if statements
Now clicking the button will make view change but we need 2 clicks to
do that
Because preinit happens then button click then session is created then
on the other pre init it will response
To fix that in the button codes both of them we will reload the page
To do that response redirect the same page we are on
But we wont type the url of the page we are in
Instead use : Request.Url.ToString() inside the response.redirect brackets