web user controls and placeholders

Discussion in 'ASP .Net' started by cyndie woodster via DotNetMonster.com, Mar 2, 2005.

  1. i had created a web user control named "uscItems.ascx"
    and a web form named "pkg.aspx"

    i added placeholder in "pkg.aspx" then in load_page i wrote this code

    dim usc1 as UserControl=LoadControl("uscItems.ascx")
    Me.PlaceHolder1.Controls.Add(usc1)

    inside my "uscItems.ascx" there r few components:image,label,checkbox
    then now i would like to change the label's text, how can i access to my
    user control components???

    thanks

    cyndie

    --
    Message posted via http://www.dotnetmonster.com
     
    cyndie woodster via DotNetMonster.com, Mar 2, 2005
    #1
    1. Advertising

  2. cyndie woodster via DotNetMonster.com

    Guest Guest

    As long as they are server control's, marked with a runat="server" and a
    valid ID then you can access them via usc1.FindControl(s).
    You could also set up public properties on usc1 that modify the text. This
    is probably the preferred method and will also be a bit faster.
    In your uscItems.ascx.cs you would just define
    public String LabelCaption
    {
    get { return MyLabelControl.Text; }
    set { MyLabelControl.Text = value; }
    }
    Then you could just go usc1.LabelCAption = "...."; Just remember that the
    control you are modifying has to have a runat="server" tag along with a
    valid ID and should also have a variable declaration in your code behind if
    the Designer did not automagically put it there already. (switching from
    design view to code) and vice versa usually triggers vs.net to automagically
    add it.


    Some sample C# code but easily adaptable to whatever .NET langauge you are
    using.
    the

    "cyndie woodster via DotNetMonster.com" <> wrote in
    message news:...
    >i had created a web user control named "uscItems.ascx"
    > and a web form named "pkg.aspx"
    >
    > i added placeholder in "pkg.aspx" then in load_page i wrote this code
    >
    > dim usc1 as UserControl=LoadControl("uscItems.ascx")
    > Me.PlaceHolder1.Controls.Add(usc1)
    >
    > inside my "uscItems.ascx" there r few components:image,label,checkbox
    > then now i would like to change the label's text, how can i access to my
    > user control components???
    >
    > thanks
    >
    > cyndie
    >
    > --
    > Message posted via http://www.dotnetmonster.com
     
    Guest, Mar 2, 2005
    #2
    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. Bill Belliveau
    Replies:
    0
    Views:
    371
    Bill Belliveau
    Aug 19, 2003
  2. buran
    Replies:
    1
    Views:
    414
    Bruno Sirianni
    Apr 6, 2004
  3. Josh
    Replies:
    1
    Views:
    9,551
    Jeffrey Palermo [MCP]
    May 26, 2004
  4. Josh
    Replies:
    1
    Views:
    201
  5. Josh
    Replies:
    1
    Views:
    247
Loading...

Share This Page