Dynamically adding a web user control to a placeholder

Discussion in 'ASP .Net' started by Stu, Jan 6, 2005.

  1. Stu

    Stu Guest

    Hi,

    I have created a Web User Control (vb.net) that I want to display on a
    placeholder on the page when a button is pressed. The control 'DeleteImage'
    is a blank control with 2 buttons added at design time (cancel/accept).
    However, if I add a reponse.write("hello world") in the page load handler
    the text appears to shhow the control is actually loding & firing to some
    extent, but there is no sign of the buttons!

    Am I missing something really basic?

    Code:
    Dim ctrl As New DeleteImage
    PlaceHolder1.Controls.Add(ctrl)

    Thanks in advance,

    Stu
    Stu, Jan 6, 2005
    #1
    1. Advertising

  2. Stu

    Karl Seguin Guest

    To load user controls you must use the Page.LoadControl:

    dim ctrl as DeleteImage = ctype(Page.LoadControl("mycontrol.ascx"),
    DeleteImage)
    PlaceHolder1.Controls.Add(ctrl)

    you can only use the new syntax when loading server controls.

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Stu" <> wrote in message
    news:...
    > Hi,
    >
    > I have created a Web User Control (vb.net) that I want to display on a
    > placeholder on the page when a button is pressed. The control

    'DeleteImage'
    > is a blank control with 2 buttons added at design time (cancel/accept).
    > However, if I add a reponse.write("hello world") in the page load handler
    > the text appears to shhow the control is actually loding & firing to some
    > extent, but there is no sign of the buttons!
    >
    > Am I missing something really basic?
    >
    > Code:
    > Dim ctrl As New DeleteImage
    > PlaceHolder1.Controls.Add(ctrl)
    >
    > Thanks in advance,
    >
    > Stu
    >
    >
    Karl Seguin, Jan 6, 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. nail

    Build control in a placeholder or like a placeholder

    nail, Sep 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    321
  2. Travis Pruitt

    Dynamically Adding User Control with Child User Control

    Travis Pruitt, Jan 13, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    170
    Travis Pruitt
    Jan 13, 2005
  3. Phoenix
    Replies:
    2
    Views:
    230
    Teemu Keiski
    Jun 6, 2005
  4. Ugur Ekinci

    Dynamically Loading User Control in PlaceHolder

    Ugur Ekinci, Nov 22, 2005, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    211
    Gokhan Altinoren
    Nov 27, 2005
  5. elkay
    Replies:
    5
    Views:
    232
    elkay
    Dec 22, 2004
Loading...

Share This Page