Home All Groups Group Topic Archive Search About
Author
9 Dec 2005 4:58 PM
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

Author
9 Dec 2005 9:36 PM
clintonG
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/






Show quote
"Howard" <howdy0***@yahoo.com> wrote in message
news:OXwBYHO$FHA.1288@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
>
>
Author
9 Dec 2005 10:03 PM
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


Show quote
"clintonG" <csgallag***@REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:%23px2ViQ$FHA.2740@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" <howdy0***@yahoo.com> wrote in message
> news:OXwBYHO$FHA.1288@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
>>
>>
>
>
Author
10 Dec 2005 1:29 AM
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/








Show quote
"Howard" <howdy0***@yahoo.com> wrote in message
news:%23ZuosxQ$FHA.3992@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" <csgallag***@REMOVETHISTEXTmetromilwaukee.com> wrote in message
> news:%23px2ViQ$FHA.2740@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" <howdy0***@yahoo.com> wrote in message
>> news:OXwBYHO$FHA.1288@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
>>>
>>>
>>
>>
>
>
Author
10 Dec 2005 2:09 AM
Howard
thanks for your help
How do you strongly type the MasterPage using MasterType?




Show quote
"clintonG" <csgallag***@REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:er%23zskS$FHA.4080@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(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" <howdy0***@yahoo.com> wrote in message
> news:%23ZuosxQ$FHA.3992@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" <csgallag***@REMOVETHISTEXTmetromilwaukee.com> wrote in
>> message news:%23px2ViQ$FHA.2740@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" <howdy0***@yahoo.com> wrote in message
>>> news:OXwBYHO$FHA.1288@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
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
10 Dec 2005 2:21 AM
Bennie Haelen
Hi Howard,

Below is an example:

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

Regards,

Bennie Haelen




Howard wrote:
Show quote
> thanks for your help
> How do you strongly type the MasterPage using MasterType?
>
>
>
>
> "clintonG" <csgallag***@REMOVETHISTEXTmetromilwaukee.com> wrote in message
> news:er%23zskS$FHA.4080@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(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" <howdy0***@yahoo.com> wrote in message
>>news:%23ZuosxQ$FHA.3992@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" <csgallag***@REMOVETHISTEXTmetromilwaukee.com> wrote in
>>>message news:%23px2ViQ$FHA.2740@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" <howdy0***@yahoo.com> wrote in message
>>>>news:OXwBYHO$FHA.1288@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
>>>>>
>>>>>
>>>>
>>>>
>>>
>>
>
>

AddThis Social Bookmark Button