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

Discussion in 'ASP .Net' started by Aussie Rules, Jul 24, 2006.

  1. Aussie Rules

    Aussie Rules Guest

    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, Jul 24, 2006
    #1
    1. Advertising

  2. RE: setting the text value of a control on the master page, from a con

    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
    >
    >
    >
     
    =?Utf-8?B?Y2xpY2tvbg==?=, Jul 24, 2006
    #2
    1. Advertising

  3. Aussie Rules

    vMike Guest

    "Aussie Rules" <> wrote in message
    news:...
    > 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, Jul 24, 2006
    #3
  4. Re: setting the text value of a control on the master page, from a

    "vMike" wrote:
    >
    > "Aussie Rules" <> wrote in message
    > news:...
    > > 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;
     
    =?Utf-8?B?R1RC?=, Jul 25, 2006
    #4
  5. Re: setting the text value of a control on the master page, from a

    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 (, 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.
     
    Walter Wang [MSFT], Jul 25, 2006
    #5
  6. Re: setting the text value of a control on the master page, from a

    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 (, 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.
     
    Walter Wang [MSFT], Jul 25, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Doug McCann
    Replies:
    1
    Views:
    1,140
    William Brogden
    Aug 5, 2004
  2. Replies:
    0
    Views:
    758
  3. Laith Zraikat
    Replies:
    3
    Views:
    1,255
    Walter Wang [MSFT]
    Jul 6, 2006
  4. Rolf Welskes
    Replies:
    7
    Views:
    1,016
    Steven Cheng[MSFT]
    Aug 22, 2006
  5. Nathan Sokalski
    Replies:
    25
    Views:
    1,498
    Nathan Sokalski
    Mar 4, 2010
Loading...

Share This Page