Programmatically Get to User Control Properties

Discussion in 'ASP .Net Building Controls' started by Newbie, Jul 13, 2005.

  1. Newbie

    Newbie Guest

    I created a User Control, called in an Asp.Net page.

    First, I've registered the control at the top of the page:
    <%@ Register TagPrefix="uc1" TagName="MyUC" Src="MyUC.ascx" %>

    Then, placed the control, as follows:
    <uc1:MyUC id="MyUC1" runat="server" TitleText="My custom text"></uc1:MyUC>

    The TitleText property is a custom property in the control that alters the text of a label web control inside of the user control, which works fine if I type text directly into the html-source portion of the web page; however, I would like to alter this text dynamically in the code-behind in the Page_Load method, dependent on a variable passed in from another link.

    When I try to do something to the effect of either
    MyUC1.TitleText = strCustomTextVariable
    OR
    uc1.TitleText = strCustomTextVariable
    I get the following error:
    Name MyUC1 is not declared

    When I try MyUC.TitleText = strCustomTextVariable, I get
    Reference to a non-shared member requires an object reference.

    How would I go about doing this? Thanks in advance.
    Newbie, Jul 13, 2005
    #1
    1. Advertising

  2. Can you show us what you have in the codebehind?

    Do you have a line like this, as with all the other web controls?
    protected MyUC MyUC1;
    Andrew Backer, Jul 14, 2005
    #2
    1. Advertising

  3. Newbie

    Newbie Guest

    Thanks. I was missing that line, which fixed the problem.


    "Andrew Backer" <> wrote in message
    news:...
    > Can you show us what you have in the codebehind?
    >
    > Do you have a line like this, as with all the other web controls?
    > protected MyUC MyUC1;
    >
    Newbie, Jul 14, 2005
    #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. =?Utf-8?B?YWJqb3Jr?=
    Replies:
    1
    Views:
    3,786
    Jeffrey Palermo
    May 5, 2004
  2. Nathan Sokalski
    Replies:
    0
    Views:
    878
    Nathan Sokalski
    Oct 17, 2005
  3. Max2006
    Replies:
    2
    Views:
    498
    Max2006
    Jul 13, 2007
  4. Adam M
    Replies:
    1
    Views:
    396
    Adam M
    Jan 23, 2008
  5. TK

    Properties for User Controls loaded Programmatically

    TK, Feb 24, 2004, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    147
    Alessandro Zifiglio
    Feb 26, 2004
Loading...

Share This Page