Sunday, November 9, 2008
To Access public members like Property of a Master Page in Child Page we need to specify @MasterType directive with virtualpath attribute pointing to MasterPage path. i.e Use the @MasterType directive to set the strong type for the master page, as accessed through the Master property.
public string masterVariable = "interviews.dotnetthread.com".
<%@ Page Language="C#" MasterPageFile="~/master/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="menu_master_Default" Title="Untitled Page" %>
<%@ MasterType VirtualPath="~/master/MasterPage.master" %>
Then in Page_Load we can access as below
sting childVar = this.Master.masterVariable;
But If we want to access master page control in child page we can access using Master.FindControl() method.
If we want to access Child Page controls in Master Page then
ContentPlaceHolder1.FindControl() method of contentplaceholder is used.
Also Read other Top Articles
- JSON Serialization in VS 2008
- Implementing Forms Authentication in Silverlight Application.
- Making GridView Rows or Individual Cells Clickable and Selectable.
- Enabling browser back button for GridView Paging and Sorting in Ajax 1.1 and 3.5 (using Visual Studio 2005/ Visual studio 2008)
- How to pass values from User Control to Page or calling Page methods from User Control.
- What is WCF?
- New features in C# 4.0
- C# to VB.NET and VB.NET to C# online free converter tools.