Once we have strongly typed the MasterPage using MasterType we can access
its members directly.
Master.categoryname = "new items";
This gets a bit more complex and requires a cast when attempting to
reference controls in the MasterPage or in the ContentPlaceHolder.
Label lbl = (Label)Master.FindControl("LabelID");
It can also require compound statements when the control is a child of
another control such as when trying to reference a TableRow that is set to
runat="server" as I've used the following example to show how such
referencing can be used to reference the row to toggle its display on and
off from the server simulating an expand/collapse event.
// Page.Controls[0].FindControl(ContentPlaceHolderID).FindControl(Con trol)
TableRow ctl =
(TableRow)Page.Controls[0].FindControl("CenterPanelContent").FindControl("Ta ble1").FindControl("R2");
<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL
http://metromilwaukee.com/
URL
http://clintongallagher.metromilwaukee.com/
"Howard" <ho*******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
how do i access a public variable in master from child pages? for example
in master.cs i have
public string categoryname = "";
i want to set categoryname ="new items" in default.aspx.cs
"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... Its very simple if you do this...
// content page
<%@ MasterType VirtualPath="~/Masters/YourMaster.master" %>
// partial class of content page
Page.Title = "Whatever";
<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/
"Howard" <ho*******@yahoo.com> wrote in message
news:OX**************@TK2MSFTNGP09.phx.gbl...i have a default.master and default.aspx
in default.aspx i would like to access a variable in default.master
pageTitle
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//pageTitle= "frist page";
}
}
this is my default.master
public partial class Default_Master : System.Web.UI.MasterPage
{
public string pageTitle= "No title";
protected void Page_Load(object sender, EventArgs e)
{
}
}
default.master html
<title><% =pageTitle%></title>
by accessing default.aspx the title should say first page. but it's not
working
Howard