473,405 Members | 2,415 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,405 software developers and data experts.

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

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
Jul 24 '06 #1
5 1793

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
Jul 24 '06 #2

"Aussie Rules" <Au*********@nospam.nospamwrote in message
news:eO**************@TK2MSFTNGP05.phx.gbl...
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"

Jul 24 '06 #3
GTB


"vMike" wrote:
>
"Aussie Rules" <Au*********@nospam.nospamwrote in message
news:eO**************@TK2MSFTNGP05.phx.gbl...
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;
Jul 25 '06 #4
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 (wa****@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.

Jul 25 '06 #5
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 (wa****@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.

Jul 25 '06 #6

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

Similar topics

3
by: Patrick | last post by:
I am dynamically creating TextArea and drop-down lists in ASP.NET using something like HtmlTextArea eachTextArea = new HtmlTextArea(); I tried to set the "name" of these TextAreas, etc. (e.g....
4
by: ¿ Mahesh Kumar | last post by:
Hi groups, I'm following Master page concept of ASP.NET 2.0, in which I'm deriving all the following page from master page for Theme. So unfortunately i'm dont get any Form Tag in my derived...
2
by: dotnetjose | last post by:
Hi Folks, My subject message pretty musch explains it. By Default the Form definition sits at the Master Page file. Is there a way I can access the setting from my Content Page that uses a...
1
by: Roland Dick | last post by:
Hello, I have a problem here with an ASP.NET website. The pages are supposed to use a single master page which just contains some images and a menu control on the top, below that is the content...
2
by: shapper | last post by:
Hello, I have a master page where my form has the Runat="server". The master page as a control place holder, named "cphContent". Then in a page which inherits from the master page I added a...
1
by: Asif | last post by:
Hi All, I did follow the MSDN article (http://msdn2.microsoft.com/en-us/ library/ms379585(VS.80).aspx ) for overriding Master Page properties by setting page title and other Meta information(...
4
by: Jason | last post by:
Hi, Here's the scenario: I have a web application that has window A and window B. A user has both window A and B open - window A is in the foreground and window B is behind it. If the...
3
by: Mick Walker | last post by:
Hi All, I have a user control on my master page, which exposes 3 public properties (all boolean). Basically by the values of these properties, the user control builds a menu to for users to...
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.