473,498 Members | 310 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamic load user controls

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
Nov 19 '05 #1
2 1385
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

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

"guoqi zheng" <no@sorry.com> wrote in message
news:36******************************@ureader.com. ..
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

Nov 19 '05 #2
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
"guoqi zheng" <no@sorry.com> wrote in message
news:36******************************@ureader.com. ..
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

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7535
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
3
3944
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which...
5
2385
by: mytestemailaccount | last post by:
Hi, Hope you can help. I am relatively new to all this but would appreciate the groups help. The scenario: I am c# and asp.net to create a web application. The web page contains a user...
7
1926
by: John | last post by:
Hi all, I need finality on this once and for all please. I have a main page which contains a couple of placeholders and within these placeholders, depending on what the user presses, I load...
0
2256
by: jonelling | last post by:
I am having a problem where the page load event is not being fired for certain user controls that I load dynamically in placeholders. Here is what I'm doing in brief, with full test code supplied...
1
1497
by: npverni | last post by:
I have a fairly complex form that needs to load and maintain the state of several different dynamic user controls. Here is the workflow: 1) A series of editable user controls (each containing...
1
2341
by: Gummy | last post by:
Hello, I am loading several user controls dynamically in OnInit() like this: ucListBoxSelections ucLocation = (ucListBoxSelections)LoadControl("UserControls/ucListBoxSelections.ascx");
5
1846
by: Gui | last post by:
Hi, I'm working in C# .net 2005 with Ajax. I have a page that loads dynamic user controls depending on the scenario. In those user controls, I create dynamic linkbuttons. The user controls are...
4
51590
Frinavale
by: Frinavale | last post by:
Introduction Sometimes, when developing web applications, we need to be able to dynamically load controls based on user selections. The following article describes a simple scenario where TextBox...
3
4341
balabaster
by: balabaster | last post by:
I've got a user control that builds a table of dynamic data based on a :LINQ class holding the data. The data is loaded using the LoadData(DataInstance) method. The table it builds contains a...
0
6998
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1416
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
651
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.