getting controls from the placeholder controls collection

Discussion in 'ASP .Net' started by msnews.microsoft.com, Sep 25, 2004.

  1. I'm adding multiple web controls to the placeholder controls collection, but
    even when doing the for each and recursion method of getting the web
    controls, I'm only getting the first web control that was added, and none of
    the others. I've tried add and addat methods when adding the controls, but
    while they appear on the form, only the first one can be retrieved. Is there
    some better documentation anyone could send me?

    -Max
     
    msnews.microsoft.com, Sep 25, 2004
    #1
    1. Advertising

  2. Hi Max, the following should work:

    Dim c As Control
    Dim sb As New System.Text.StringBuilder
    For Each c In PlaceHolder1.Controls()
    sb.Append(c.ID)
    sb.Append("<br>")
    Next
    Response.Write(sb.ToString())
    This code just references each child in the placeholder's control collection
    and grabs its id.. but you should be able to manipulate the child controls in
    whatever way you like inside the for/each statement.
    ie: lets say the 2nd control on the placeholder's collection was a Listbox..
    and you wanted to add an item to the listboxe's items collection .. you could
    do that inside the for each statement by doing this:

    Dim c As Control
    For Each c In PlaceHolder1.Controls()
    If TypeOf (c) Is ListBox Then
    CType(c, ListBox).Items.Add("New Item")
    End If
    Next

    Thanks,
    -Chris




    "msnews.microsoft.com" wrote:

    > I'm adding multiple web controls to the placeholder controls collection, but
    > even when doing the for each and recursion method of getting the web
    > controls, I'm only getting the first web control that was added, and none of
    > the others. I've tried add and addat methods when adding the controls, but
    > while they appear on the form, only the first one can be retrieved. Is there
    > some better documentation anyone could send me?
    >
    > -Max
    >
    >
    >
     
    =?Utf-8?B?Q2hyaXMgTW9oYW4=?=, Sep 26, 2004
    #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. Dylan
    Replies:
    5
    Views:
    444
    Daniel T.
    Mar 22, 2005
  2. Pradeep
    Replies:
    2
    Views:
    695
    Patricia Shanahan
    Jan 24, 2007
  3. Øyvind Isaksen
    Replies:
    1
    Views:
    1,027
    Øyvind Isaksen
    May 18, 2007
  4. nail

    Build control in a placeholder or like a placeholder

    nail, Sep 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    370
  5. Denny Smolinski via .NET 247

    Dynamic Controls, Placeholder, Retrieve Information from Dynamic Controls

    Denny Smolinski via .NET 247, May 4, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    504
    Eidolon
    May 4, 2004
Loading...

Share This Page