Total Pageviews

3/24/2010

Strongly-typed access to Master Pages controls:



The PreviousPageType directive isn't the only one that provides strongly-typed access to controls. If you have public properties defined in a Master Page that you'd like to access in a strongly-typed manner you can add the MasterType directive into a page as shown next (note that the MasterType directive also allows a TypeName to be defined as with the PreviousPageType directive):

<%@ MasterType VirtualPath="MasterPage.master" %>

You can then access properties in the target master page from a content page by writing code like the following:
this.Master.HeaderText = "Label updated using MasterType directive with VirtualPath attribute.";

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Affiliate Network Reviews