master page

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
 
H

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
 
C

clintonG

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

Howard

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
 
B

Bennie Haelen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top