Dynamically load Web User Controls

  • Thread starter Thread starter Jack David
  • Start date Start date
J

Jack David

I have a number of web user controls that I want to be able to load into a
page. I want to be able to define what controls to include in the page, and
what order they should appear in.
I am using C#

Example:
Web Control 1 = Greeting
Web Control 2 = Select Credit Card Type

If Session ScriptID = A then I would want to display
Greetting
Select Credit Card Type

If Session ScriptID = B then I would want to display
Select Credit Card Type
Greeting

If Session ScriptID = C then I would want tp display
Greeting

Can I store the location and order in a database table and somehow load this
into the page when it is rendered??

Thanks
Jack David
 
I have done similar stuff before by adding a panel; "pnlPlaceholder1" at the
desired location, then in code "ctlMyWebControl=new MyWebControl();
pnlPlaceholder1.Controls.Add(ctlMyWebControl);"

This way I get a reference to the control in the main page and I add it
dynamically. In my situation I had to load several instances of the same
control, and address them from the main form - this was the solution.

Regards,
Harald Bjorøy
www.ulriken-consulting.no
 
Back
Top