How To: Set Label Text Property In Master Page (From Subscribing Page)?

Discussion in 'ASP .Net' started by Joey, May 22, 2007.

  1. Joey

    Joey Guest

    asp.net 2/C#/VS2005

    How do i set the text property for a label control on my master page?
    I am able to use...

    this.Master.FindControl("lblMyLabel").Visible = false;

    ....to hide the label. That works fine. However, when trying to set the
    text property, I can see there is no "Text" property. So I thought a
    cast would work...

    ((Label)(this.Master.FindControl("lblMyLabel")).Text = "My Text";

    ....but when I do this nothing happens. No error...just nothing.

    What am I doing wrong?

    JP
    Joey, May 22, 2007
    #1
    1. Advertising

  2. Joey

    Mark Rae Guest

    "Joey" <> wrote in message
    news:...

    > ((Label)(this.Master.FindControl("lblMyLabel")).Text = "My Text";


    That should certainly work...

    > ...but when I do this nothing happens. No error...just nothing.


    Are you maybe clearing the property later...?

    If you put a breakpoint on the line in question, do you see the value of the
    property change...?

    Alternatively, do you have more than one MasterPage...?


    --
    http://www.markrae.net
    Mark Rae, May 22, 2007
    #2
    1. Advertising

  3. Joey

    Joey Guest

    On May 22, 10:22 am, "Mark Rae" <> wrote:
    > "Joey" <> wrote in message
    >
    > news:...
    >
    > > ((Label)(this.Master.FindControl("lblMyLabel")).Text = "My Text";

    >
    > That should certainly work...
    >
    > > ...but when I do this nothing happens. No error...just nothing.

    >
    > Are you maybe clearing the property later...?
    >
    > If you put a breakpoint on the line in question, do you see the value of the
    > property change...?
    >
    > Alternatively, do you have more than one MasterPage...?
    >
    > --http://www.markrae.net


    I did not have the code in the Page_PreRender event handler. After I
    moved it there, it worked.
    Joey, May 23, 2007
    #3
    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. Tina
    Replies:
    3
    Views:
    544
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Oct 13, 2005
  2. Doug McCann
    Replies:
    1
    Views:
    993
    William Brogden
    Aug 5, 2004
  3. gabriel
    Replies:
    2
    Views:
    740
    gabriel
    Dec 21, 2004
  4. Nathan Sokalski
    Replies:
    25
    Views:
    1,410
    Nathan Sokalski
    Mar 4, 2010
  5. Knut Krueger
    Replies:
    8
    Views:
    257
    Knut Krueger
    Aug 20, 2013
Loading...

Share This Page