Random Ramblings

ASP.NET Master Pages

by admin on Dec.04, 2008, under Programming

Now that almost the whole of my working time is spent developing the new online system, I’ve been toying with a number of different structures for the pages.

I first had separate pages for each function, which worked well, but made the the tree a little messy.  I then moved to having one individual page for each of the three user views (administrator, staff member, and client).  All of the controls and functions were contained within that single page.

This was also working well, until I had to create a control which dynamically loads another control (using the Page.LoadControl function).  For the postbacks to work and the events contained within the dynamically-loaded control, this had to be done in an OnInit method.  Which means every single time the page loads on postback (which just to get to that control from login was at least 3), this method must be called.

One of other goals of having the one page per user view idea would be to have a consistent look and feel in each of these views.  I noticed a friend’s tweet about Master Pages, and checked it out in my ASP.NET “bible”, and thought it should be easy enough to implement.

I set out to implement it as a test which again worked incredibly well.  But, I came across a need to access a property of the Master Page from the Content Page.  Yes, I could cast the call to Master (such as (MasterPage)Master.SomeCustomProperty), but there’s actually a directive in ASP.NET to automatically provide this cast to all calls to Master.

Simply add <%@ MasterType VirtualPath=”~/path/to/MasterPage.Master” %> to your content page and any call to Master will automatically be of the type specified in the VirtualPath property.

As part of the Master Page migration, I have created a Content Page for each of the areas within the user view structure, and I’m still contemplating whether to split these into the individual functions.  This means I will have come full circle from the first idea, but at least I’d have a consistent look and feel and will be able to easily modify the display.


Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...