Getting Master Page Properties

21-08-2007 18:14:48

The last days I have been working on quite exiting projects at work and private, and thats why i want to share some programming experience.

Here we go with another code trick to access properties on a MasterPage much easier than it make all other kinds of casting to get the information.

I you have a MasterPage called Default.master in the root of my website, you would typically cast the Master and then access the different controls by FindControl then. But instead of using FindControl, which often is quite heavy!, add this line into your .aspx file, just below the <%Page%> page tag.

<%@ MasterType VirtualPath="~/Default.master" %>

Now you should be able to access or set some properties on the MasterPage, by typing this line below in your .aspx file codebehind

Master.PropertyName = PropertyValue;

I hope this code hints is going to save you a lot of time :)

Relaterede blog indlæg



Kommentarer

Der er ingen kommentarer skrevet

Tilføj en kommentar

Navn
Email (Bliver ikke vist på siden)
Hjemmeside
Hvad er 1 + 2?
Kommentar
 
Copyright © 2005 - 2010 Daniel Nøhr. All rights reserved