Add a Master Page to the Web Project
Right-click on the project and select Add->Add New Item to add a new MasterPage called "Site.Master" to the project:![](http://webproject.scottgu.com/CSharp/MasterPages/step1.png)
![](http://webproject.scottgu.com/CSharp/MasterPages/step2.png)
![](http://webproject.scottgu.com/CSharp/MasterPages/step3.png)
If you switch into WYSIWYG design mode the Site.Master will look like this:
![](http://webproject.scottgu.com/CSharp/MasterPages/step4.png)
Now we are ready to have pages in our site pick up and use the master-page file.
Update Default.aspx and DataSample.aspx to use the Master Page
Open the default.aspx page we built in an earlier tutorial, and switch to HTML source-view. To update it to use the master-page go to the top <%@ Page %> directive and add a "MasterPageFile" attribute:![](http://webproject.scottgu.com/CSharp/MasterPages/step5.png)
Then delete the static html previously on the page, and add an
![](http://webproject.scottgu.com/CSharp/MasterPages/step6.png)
![](http://webproject.scottgu.com/CSharp/MasterPages/step7.png)
![](http://webproject.scottgu.com/CSharp/MasterPages/step8.png)
![](http://webproject.scottgu.com/CSharp/MasterPages/step9.png)
![](http://webproject.scottgu.com/CSharp/MasterPages/step10.png)
Add a Web.SiteMap to the Web Project
Right-click on the project and select Add->Add New Item to add a new Site Map file called "Web.SiteMap" to the project:![](http://webproject.scottgu.com/CSharp/MasterPages/step11.png)
![](http://webproject.scottgu.com/CSharp/MasterPages/step12.png)
![](http://webproject.scottgu.com/CSharp/MasterPages/step13.png)
![](http://webproject.scottgu.com/CSharp/MasterPages/step13.5.png)
This will then data-bind the Treeview against the web.sitemap file we created above. Choose the auto-format menu item in the "common tasks" menu and format it as "simple":
![](http://webproject.scottgu.com/CSharp/MasterPages/step14.png)
Note how the tree-view menu shows the current web.sitemap's hierarchy at design-time.
Press the F5 or Ctrl-F5 key to build and run the site:
![](http://webproject.scottgu.com/CSharp/MasterPages/step16.png)
![](http://webproject.scottgu.com/CSharp/MasterPages/step15.png)
Notice how the tree-view menu automatically highlights (by underlining - although you can style it however you want) the current node in the site-hierarchy as a user navigates around the site.
Click here to go to the next tutorial.
by webproject.scottgu.com
No comments:
Post a Comment