Master Pages and User Controls in .NET 2.0

written by Ryan Olshan on Sunday, March 26 2006

One of the great mysteries of .NET 2.0 is how to reference the class of a master page or user control from code-beside. This is where the MasterType and Reference directives come into play.

Master Page (from content page)

<% @ MasterType TypeName="ClassName" %>

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

User Control (from web form)

<% @ Reference Control VirtualPath="~/VirtualPath/UserControl.ascx" %>

After adding the MasterType or Reference directive, you should then be able to reference the master pages or user controls class from code-beside.

Kick this post on .NET Kicks

Similar Posts

  1. Dev Connections Day 2
  2. MagicAjax - Easy as 1, 2, 3
  3. EnsureChildControls

Post a comment