Dynamically adding a web user control to a placeholder

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
 
K

Karl Seguin

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top