You are not Logged in
Would you like to Login or Register

Today is: Friday, 21 November, 2008
Check this months hot topics

Typed Masterpage reference

ASP.NET master pages are pretty handy and here is a simple tip to make them even easier to use.

Using the MasterType reference in your content page allows you to refer to your master page properties without having to cast it to your master page type everytime.

For example...

<%@ MasterType TypeName="myMasterType" %>

allows me to write...

this.Master.myProperty = "value";

rather than...

((myMasterType)this.Master).myProperty = "value";

Which saves you a little typing and provides intellisense

kick it on DotNetKicks.com del.icio.us digg Mister Wong YahooMyWeb Reddit Furl Spurl blogmarks
Dave Howard Skype
Author : Dave Howard
Published : Friday, 22 September, 2006

I have been involved in IT development for the last 10 years - a lot of it around desktop applications and telecoms.

Comments

phayman said:

Nice little find, thanks Dave.

September 25, 2006 - 12:39 PM

jaycat said:

also in the mastertype adding the following aslo works: virtualpath="~/MasterPage.master"

September 26, 2006 - 10:17 PM

phayman said:

Just have to say again... excellent find, I've been using this loads, makes life soooo much easier!!

September 29, 2006 - 9:34 PM

Add Comment

Enter your comment below and it will be submitted for moderation.

Your Name

Add Tag

Please enter tags for this article, seperated by semi-colon ;

View Tag's by : # articles | # views