Within the code of a content page, how do you say set the .text value of a
label thats on the master page...
ThanksLabel MasterPageLabel = (Label)Master.FindControl("MasterPAgeLAbelID");
MasterPageLabel.Text ="some words";
Master.FindControl returns a reference to the master page control.
"Aussie Rules" wrote:
Quote:
Originally Posted by
Hi,
>
Within the code of a content page, how do you say set the .text value of a
label thats on the master page...
>
Thanks
>
>
>
"Aussie Rules" <AussieRules@.nospam.nospamwrote in message
news:eOMr07yrGHA.4424@.TK2MSFTNGP05.phx.gbl...
Quote:
Originally Posted by
Hi,
>
Within the code of a content page, how do you say set the .text value of a
label thats on the master page...
>
Thanks
>
>
Another solution is to have a class for your master page (say its called
myMP) with
properties. Then in you content code you do the following.
In master page code
Public Property MyLabelText() as string
Get
return MyLabel.Text
End Get
Set (MyLabelText as string)
MyLabel.text = MyLabelText
End Set
End Property
In your content page code
dim mp as myMP = ctype(page.master, myMP)
mp.MyLabelText = "My label text"
"vMike" wrote:
Quote:
Originally Posted by
>
"Aussie Rules" <AussieRules@.nospam.nospamwrote in message
news:eOMr07yrGHA.4424@.TK2MSFTNGP05.phx.gbl...
Quote:
Originally Posted by
Hi,
Within the code of a content page, how do you say set the .text value of a
label thats on the master page...
Thanks
Another solution is to have a class for your master page (say its called
myMP) with
properties. Then in you content code you do the following.
>
In master page code
>
Public Property MyLabelText() as string
Get
return MyLabel.Text
End Get
Set (MyLabelText as string)
MyLabel.text = MyLabelText
End Set
End Property
>
In your content page code
>
dim mp as myMP = ctype(page.master, myMP)
mp.MyLabelText = "My label text"
If I am designing common code-behind functionality, but like to vary the
look and feel of my master pages I find that having the master pages
implement a standard interface is a good way to go.
That way the properties are wrapped up in one place, and the content page
code need never change because they can always access the property regardless
of the master page they reside within. e.g.
((ISomeCommonMasterPageStuff)this.Master).Title = value;
Thanks for other community members useful input.
By the way, you actually can instruct the ASP.NET page parser to generate a
strongly typed Master property in the content page by adding an @.
MasterType directive:
<%@. MasterType VirtualPath="~/MasterPage.master" %>
Then you can directly use "Master.MyLabelText" to access the public
property of the master page without type cast.
However, since the Label control on the master page is protected, you still
need to wrap its Text property in a public property, like MyLabelText in
vMike's sample code.
I also think GTB's approach is better if you have several master pages.
Hope this helps. Please feel free to post here if anything is unclear.
Regards,
Walter Wang (wawang@.online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
And here's some useful links about ASP.NET master page:
#ASP.NET 2.0 - Master Pages: Tips, Tricks, and Traps
http://www.odetocode.com/Articles/450.aspx
http://www.odetocode.com/Articles/419.aspx
Regards,
Walter Wang (wawang@.online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
0 comments:
Post a Comment