Dynamically adding a web user control to a placeholder

  • Thread starter Thread starter Stu
  • Start date Start date
S

Stu

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
 
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
 
Back
Top