Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > setting the text value of a control on the master page, from a content page

Reply
Thread Tools

setting the text value of a control on the master page, from a content page

 
 
Aussie Rules
Guest
Posts: n/a
 
      07-24-2006
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?Y2xpY2tvbg==?=
Guest
Posts: n/a
 
      07-24-2006

Label MasterPageLabel = (Label)Master.FindControl("MasterPAgeLAbelID");
MasterPageLabel.Text ="some words";

Master.FindControl returns a reference to the master page control.

"Aussie Rules" wrote:

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

 
Reply With Quote
 
 
 
 
vMike
Guest
Posts: n/a
 
      07-24-2006

"Aussie Rules" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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"



 
Reply With Quote
 
=?Utf-8?B?R1RC?=
Guest
Posts: n/a
 
      07-25-2006


"vMike" wrote:
>
> "Aussie Rules" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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;
 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      07-25-2006
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 ((E-Mail Removed), 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.

 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      07-25-2006
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 ((E-Mail Removed), 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting the value of a Master page's control's property using a property of the Master page Nathan Sokalski ASP .Net 25 03-04-2010 03:42 AM
Missing Content Placeholder in nested master content page John ASP .Net 2 01-15-2008 11:48 AM
Master-Content in Asp.net - How to set individual Head for each content page Rolf Welskes ASP .Net 7 08-22-2006 02:47 PM
Setting the Page Title using local resources for a content page in a master page Laith Zraikat ASP .Net 3 07-06-2006 01:23 AM
limit on number of content placeholders(which are editable in content pages) in master page nemesis.saurabh@gmail.com ASP .Net 0 05-25-2006 04:44 AM



Advertisments