Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading user controls dynamically

How to load a user control dynamically in a page?
I have a page that contains radioButtons. Each click on a radio button loads a user control (.ascx) in the page.
What I am doing is loading all controls at the same time, but set their visibility to false. When a user clicks a radiobutton I set the visibility of the specific user control to true.
As a result I am loading all the user controls on each postback.
Is there any other possible way of doing this?

like image 382
scatman Avatar asked Nov 29 '10 08:11

scatman


1 Answers

Add a div with runat server on the page with an id "divControls" for example.

Asp allow you to load a user control ".ascx" dynamically.

The below code should solve your problem.

Control ctrl = Page.LoadControl("UserControlPath");
divControls.Controls.Clear();
divControls.Controls.Add(ctrl);
like image 199
Ghyath Serhal Avatar answered Sep 20 '22 05:09

Ghyath Serhal