Reference Controls from MasterPage

To reference controls from a master page in a normal page use the following syntax:

Ex. Reference the Head Html tag of the Master Page from a normal page to add scripts in the head. Set the Head as runat=”server” and give id=”Head”, then enter the following syntax:

HtmlHead headTag = ((HtmlHead)((MasterPageName)this.Master).FindControl(“Head”));

Hope this helps. Btw this will mostly be used in Visual Studio 2005 since in the new versions, you can add an ContentPlaceHolder in the Head tag of the Master page and insert any scripts in the PlaceHolder on the page

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: