Dynamic User Controls

A

AJ

Hello, I have a page with user controls 1,2,3.

1-will always load in the page

2 or 3 will load depending on the action that is taken in
1.

There are events/delegates in 1 that will tell 2 or 3 to
load with data. The only way I'm accomplishing this now
is I'm loading 2 and 3 on the page's init event, setting
their visible properties to false and just set visible
properties for 2 or 3 to true when a certain event is
raised from 1.

However, I don't want to do that I just want to
LoadControl and Controls.Add 2 or 3 depending on the
action in 1. I tried this but the event doesn't fire
because it is not loaded in the Page's Init event.

I guess I could have a hidden field that will tell init
what to load but is their a better way?
 
J

John Saunders

AJ said:
Hello, I have a page with user controls 1,2,3.

1-will always load in the page

2 or 3 will load depending on the action that is taken in
1.

There are events/delegates in 1 that will tell 2 or 3 to
load with data. The only way I'm accomplishing this now
is I'm loading 2 and 3 on the page's init event, setting
their visible properties to false and just set visible
properties for 2 or 3 to true when a certain event is
raised from 1.

However, I don't want to do that

Why not?
 
A

AJ

Well I just don't want to load 2 or 3 if I don't need to
but I figured how to do it. Just set a hidden form after
1 does some stuff, so on the next round trip the page will
know what to load based on the hidden form.

thanks,
AJ
 
J

John Saunders

I'm glad it's working for you.

Just a word. Unless you're talking about a page that gets hit thousands of
times per second, the overhead of loading two user controls which will not
render anything because they're Visible property is false, is insignificant.
As fast as modern machines run, it might have been more efficient to take
the tiny performance hit rather than spend the time to learn how not to take
the tiny performance hit. In fact, it's possible that your solution performs
worse than just loading all the controls.
 

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,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top