dynamic load user controls

G

guoqi zheng

Dear Sir,

I have a menu page (main.aspx") with a placeholder on it. This placeholder
will load a a main menu item user controls (mainmenu.ascx), on this page,
there are a few menu items, When user clicks one of those menu items,
placeholder will be clean and load another user control (e.g. uc1test.ascx).


I have below code on click event at mainmenu.ascx, obviously these code did
not work out. What did I do wrong here?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.
EventArgs) Handles Button1.Click

Dim abc As PlaceHolder = CType(FindControl("PlaceHolder1"), PlaceHolder)
Dim uctest1 As Control = LoadControl("uc1test.ascx")
abc.Controls.Clear()
abc.Controls.Add(uctest1)

End Sub

Regards,

Guoqi Zheng
http://www.ureader.com
 
K

Karl Seguin

Can you be a little bit more specific? What isn't working? Is the event
handler (Button1_Click) being hit? if not, you need to re-add the
mainmenu.ascx user control in init or onload in order for the event to fire.

Karl
 
S

S. Justin Gengo

Guoqi,

I have some simple samples of dynamically adding controls to a page that I
think will help you. You may find the sample code at:
http://www.aboutfortunate.com?page=codelibrary

Type "dynamic controls" into the search box and you'll see the relevant
samples.

If you have any questions after looking at the sample code feel free to
email me.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 

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

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top