473,395 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

master page

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
Dec 9 '05 #1
5 2068
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

Dec 9 '05 #2
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


Dec 9 '05 #3
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



Dec 10 '05 #4
thanks for your help
How do you strongly type the MasterPage using MasterType?


"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:er****************@TK2MSFTNGP14.phx.gbl...
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



Dec 10 '05 #5
Hi Howard,

Below is an example:

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

Regards,

Bennie Haelen


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


"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:er****************@TK2MSFTNGP14.phx.gbl...
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
>
>


Dec 10 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Michael Herman \(Parallelspace\) | last post by:
1. What are some compelling solutions for using Master/Content pages with Web Pages? 2. If a content area has a web part zone with web parts, what is the user experience like when "editting" the...
2
by: Jon Spivey | last post by:
Hi, Using VS 2005/VB.net. I need to add a meta description tag and change a stylesheet link from a page based on a master page. Found this article...
3
by: ivanpais | last post by:
Hi, I have a Web User Control, Lets say "Foo.ascx", that contains a button "btnFoo". I have a Master Page "Bar.master", that has a label "lblBar". This label is exposed by a public property...
17
by: Rob R. Ainscough | last post by:
Again another simple concept that appears NOT to be intuitive or I'm just stupid. I've read the WROX book and the example doesn't actually show how the .master page links in the other content...
2
by: SR | last post by:
I have started a web site using ASP.NET 2.0. I would like to centralize all of my classes in a StyleSheet but I cannot figure out how to link the StyleSheet to a Content Page since there is no...
0
by: Managed Code | last post by:
Hello All, Here is my issue and thanks in advance for any assistance. I have a base page with a dropdownlist that fires an event with the selected index. The content page catches the event and...
4
by: Boris Yeltsin | last post by:
OK, on my Master Page I have a control: <a id="hypTabAccount" href="#" runat="server">Account</a> Now, in the code-behind (Root.master.vb) I can refer to it simply thus: ...
7
by: Just Me | last post by:
Hi I have a master page with a control on it, but I need to set a property of that control from the content. my master page is called Admin.Master and the class is Admin. I have tried this
6
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
I am trying to access a Public property on a Master Page from a Base Page. On the content pages I have the MasterType Directive set up as follows: <%@ MasterType virtualpath="~/Master.master" %>...
5
by: =?Utf-8?B?bXVzb3NkZXY=?= | last post by:
Hi guys I'm trying to make my code as streamlined as possible, and add CSS file references dynamically when they are required, for example, if a page contains a webcontrol, then the related CSS...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.