Recent Posts
Calendar
November 2013
S M T W T F S
« Oct    
 12
3456789
10111213141516
17181920212223
24252627282930

Posts Tagged ‘master page’

How to properly access controls in the Master Page

One of the great new features in ASP.NET 2.0 has been the ability to use master pages to layout the common elements of the web site.  This certainly works better than top and bottom include files or top and bottom Web User Controls.  But at least with the user controls, if we wanted to access a control within it, the method to do so was pretty straight forward.  All you had to do was expose the control as a public property.  Or, better, create a pass through property on the control that sets or retrieves the inner control’s property.  By doing this, you could turn a side bar element on or off (as an example.)

While you can expose elements of a master page in a similar manner, anyone who’s done this knows there are a few gotchas along the way.  I’m going to tell you how to avoid the gotchas and you’ll have the added benefit of being able to access the controls on the master page even if you decide to use a different master page without having to change any code other than the master page directive at the top of the aspx page.

Read the rest of this entry »