How to dynamically cast a user control

Joined
Apr 28, 2009
Messages
1
Reaction score
0
Hello,

I have an application that is loading user controls, something like:
var w = LoadControl(this.WidgetInstance.Widget.url);
WidgetBodyPanel.Controls.Add(w);

I have a data table with my various url's that point to use controls in it.

The issue is that some of the user controls need additional parameters. I keep track of the type of user control in the data table ("ServicesWidget" for example), along with the additional parameters ("EndUserRegionId" for example).

But I need to cast the control to the correct type to be able to set the parameters.

If I were hardcoding it, it would look something like:
var w = (ServicesWidget)LoadControl(this.WidgetInstance.Widget.url);
w.EndUserRegionId = 1;

But, I do not know how to dynamically cast a user control.

Thank you for your help,
Sammer
 

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,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top