GeekZilla
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
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.
jaycat said:
also in the mastertype adding the following aslo works: virtualpath="~/MasterPage.master"
phayman said:
Just have to say again... excellent find, I've been using this loads, makes life soooo much easier!!
Paul said:
yet again I find myself referring to this article
Ben van Enckevort said:
Thank you, SO much. I have been trying to find this answer for too long