conditional loading of ascx controls.

S

sameerpande

Hello friends
I have 5 ascx controls on a aspx page, and i have to show one control at a time. These all controls are dyanamic and user can traverse from one control to other by some conditions ,but right now my controls gets loaded whenever i come to this page,i want to restict that and want to load each control when it is required
right now i have implemented the logic for conditional rendering of these controls but in this case all controls gets loaded and initilize the all the required conditions.
 
J

Jacques

If I understand you correctly you want to be able to add the user control
only when certain conditions are met!?

If that is the case then there is the option to add a placeholder control to
the page in the position where you intend the contents of the control to
appear.

Remove the 5 current controls from the page.

Wherever it is that you are validating the user input, which should allow
the next control to become available you could use code such as this to add
the relevant User Control

placeHolder1.Controls.Add(Page.LoadControl("../UserControls/myControl.ascx")
;

Hope that helped.

sameerpande said:
Hello friends ,
I have 5 ascx controls on a aspx page, and i have to show one control at
a time. These all controls are dyanamic and user can traverse from one
control to other by some conditions ,but right now my controls gets loaded
whenever i come to this page,i want to restict that and want to load each
control when it is required.
right now i have implemented the logic for conditional rendering of these
controls but in this case all controls gets loaded and initilize the all the
required conditions.
 
R

Robert Koritnik

U should use LoadControl method for this, but if you have postbacks, you
should be aware of the viewstate problems. You can load the appropriate ASCX
in the Init phase of the page, but you should ignore ProcessPostBack
exceptions due to different fields used on different controls. That way your
controls won't load until you explicitely call LoadControl. One other good
thing is that your viewstate won't have all items os all controls but only
those that will dynamicly be loaded. PartialCachingControl will have it's
instance when put in some container, not before. if you'll have problems
with setting properties before the control is put inside container.

--
RobertK
{ Clever? No just smart. }


sameerpande said:
Hello friends ,
I have 5 ascx controls on a aspx page, and i have to show one control at
a time. These all controls are dyanamic and user can traverse from one
control to other by some conditions ,but right now my controls gets loaded
whenever i come to this page,i want to restict that and want to load each
control when it is required.
right now i have implemented the logic for conditional rendering of these
controls but in this case all controls gets loaded and initilize the all the
required conditions.
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top