Web Form Master Pages in Visual Studio 2008



The way you use Master pages has changed in Visual Studio 2008. Remember, how in Visual Studio 2005 when you add a new Web Form in ASP.NET applications - you get to choose a master page to apply to the Web form. If you choose to use a Master page - then the page that is added, when you check the HTML code for that page - it is stripped of all the standard HTML tags - only the Page directive and the tags are available. This is a Content page.

In Visual Studio there are two types of Web Forms available - Web Form and the Web Content Form.

The Web Form is a standard Web Form - without the Master page, with its HTML code like a standard HTML page. Whereas, the Web Content Form is the one to which you can attach a Master page.

The Web Form page also has a MasterPageFile property. But, if you create a Web Form and then set the MasterPageFile property to link to your Master page you will get a run time error.

Content controls have to be top-level controls in a content page or a nested master page that references a master page.

This is because content pages must not have another other HTML tags or controls.

If you want to use Master Pages use Web Content Form, otherwise use the Web Form.

Another nice feature in Visual Studio 2008 - is that in that in the top right corner of the Design window of the Web content page is a link to the Master page that this page is linked to. Also, you can now see the source and the design view tiled in the design area.
Tags: , , ,
Hot on Web:


About author