|
ASP.NET 2.0: Referencing Master Page Members |
|
Page 2 of 2
.
.

The < span > element marked runat=server is mapped to an HTMLGenericControl object and its text content is exposed through the InnerText property. This property is wrapped by a new public property “SubTitle” that gets and sets the value of the InnerText property on the < span > tag.
Now this property can be invoked from the master if the SubTitle propertyis defined on the MasterPage class. This is because the MasterPage class represents the masterpage object which is compiled at runtime. The ClassName attribute on the @Master directive allows the assignment of user defined names to the master page class. Therefore the master property must be cast to the actual type to be able to call custom properties. The following code will have to be added to the content page
((MasterPage)Master).SubTitle= “Welcome”;

Now add the following code to the content page.
< script runat= “Server” >
.........Void Page_Load(object sender, EventArgs e)
.........{
..................Master. SubTitle = “Welcome”;
.........}
< /Script >

Trackback(0)

|