master page

  • Thread starter Thread starter Howard
  • Start date Start date
H

Howard

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
 
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
 
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(Control)
TableRow ctl =
(TableRow)Page.Controls[0].FindControl("CenterPanelContent").FindControl("Table1").FindControl("R2");

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/
 
thanks for your help
How do you strongly type the MasterPage using MasterType?




clintonG said:
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(Control)
TableRow ctl =
(TableRow)Page.Controls[0].FindControl("CenterPanelContent").FindControl("Table1").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 said:
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
 
Hi Howard,

Below is an example:

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

Regards,

Bennie Haelen



thanks for your help
How do you strongly type the MasterPage using MasterType?




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(Control)
TableRow ctl =
(TableRow)Page.Controls[0].FindControl("CenterPanelContent").FindControl("Table1").FindControl("R2");

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/








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


message
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/







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
 
Back
Top