Tim Weaver

A .NET Blog

<November 2008>
SuMoTuWeThFrSa
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456


Navigation

Work

Subscriptions

Post Categories



Wednesday, September 08, 2004 - Posts

VS 2005 Master Pages -- Part I
I've been playing around with the Beta 1 release of VS 2005 specifically looking at Master pages and how they will impact our development. We have some rather complex problems surrounding our presentation layer and pathing, and we are hoping to be able to leverage Master Pages to help alleviate some of those issues.

I setup a few scenarios that I wanted to test out (First 3 are in this post, remaining are in part 2):
  • Simple Master Page
  • UserControl with Shared Code Beside (partial class)
  • Nested Master Page
  • Dynamically loaded Master Page
  • Dynamically loaded User Control Inside Master Page
 
What I learned in the first couple of hours:
Beta 1 is definitely still Beta. I had a number of odd issues where I ended up shutting down VS to correct
Getting code beside to work for a UserControl was a time consuming task.
This is probably my fault for not knowing how, but getting it setup correctly took way too long.
VS seems geared towards putting the code in a single file for usercontrols, which I didn't want to do.
I just found the 'Put code in separate file' checkbox on the add new item dialog. I guess I should have looked closer the first time.
The new datasource controls won't work with properties.
I coded up my pages and the controls before actually adding any data.
When I went to attached the ObjectDataControl to my custom object it couldn't find the property I setup to return the custom collection. I had to add a method.
The other thing I don't really like about these controls is that they don't support sorting a custom collection.
It's easy to forget the RunAt='Server' Tag in your MasterPages.
I find I keep forgetting this tag, everything compiles correctly, however
the page throws an error when you attempt to browse to it.
Simple Master Pages
Not much to report here. Creating a MasterPage is dirt simple
  • Right-click Add-New Item and select MasterPage
  • Add your asp:ContentPlaceHolder controls to the page for any content areas
    I found it makes sense to add your default HTML to the content placeholder. That way your page can either accept the default or override by adding a asp:content control that uses your placeholder
<asp:ContentPlaceHolder ID="pageHeaderContentPlaceholder" Runat="server">
<table bgcolor="#e7e6e6">
<tr>
<td><a href="http:\\www.monster.com">Monster.com</a> </td>
<td> </td>
<td><a href="http:\\network.monster.com">Network.Monster.com</a></td>
<td> </td>
<td><a href="http:\\my.monster.com">My.monster.com</a></td>
</tr>
</table>
</asp:ContentPlaceHolder>
Simple User Control with Shared Partial Class
Much like the master pages this is fairly simple
  • Right-click Add-New Item and select UserControl
  • Check the Create code in separate file checkbox
If you don't create the code in a seperate file and decide you want to later Then it is a little more convoluted:

At first I tried to create a class and name it the same as what it would have been named had I used VS to create the code beside.

However when I went to compile it complained that the class already existed. Instead I created my class, marked it as partial and set the .ascx page attributes: ClassName and CompileWith to be the new class name.

You will have to put the class into the project hierarchy not into the code folder. That did the trick. The only thing I don't like is that the new class doesn't show up underneath it's parent ascx file like it would had I used the dialog to create it.
Nested Master Pages
Nesting Master pages provides a centralized way to create a consistent look and feel
  • Right-click Add-New Item and select MasterPage
  • Select create code in separate file
  • Add tag: MasterPageFile="your master page name" to your page directive
Nested Master pages aren't currently supported in the IDE so you have to do all your work in the code view.

You can't 'inherit' a ContentPlaceHolder from a nested parent master page. So if you have a placeholder that you want to be able to use in your actual content page you have to add a content tag and inside of it add another placeholder:

<asp:Content ContentPlaceHolderID="pageBodyContentPlaceHolder" Runat="server">
  <asp:ContentPlaceHolder ID="pageBodyOverride" Runat="Server"></asp:ContentPlaceHolder>
</asp:Content>

Then the pageBodyOverride content placeholder will be available in your page. You use it by adding:
<asp:Content ContentPlaceHolderID="pageBodyOverride" Runat="Server"> whatever mark up you want </asp:Content>

posted Wednesday, September 08, 2004 6:27 PM by icodemarine




Powered by Dot Net Junkies, by Telligent Systems