PDA

Click to See Complete Forum and Search --> : Possible?


Ryan
Jan 25th, 2005, 11:21 AM
Basically I have a bunch of web user controls (.ascx) files that I want to be dynamically loaded from a db. Every single one of these controls have a value that can be passed into it. [Value] so If I was to declare a new object as one of these web user controls, I could do a myControl.Value = "whatever".

So, my question is, since I want to dynamically load them using something like this:


Public oCtrl As Control
oCtrl = LoadControl(objRS("myCtl"))
'here is where I want to pass in the value
oCtrl.Value = "whatever I want"
Panel1.Controls.Add(Me.oCtrlDemo)

Is there some way I could add a "Value" property to the general Control class?

axion_sa
Jan 25th, 2005, 11:46 AM
Short answer: no.

Long answer: you can do this quickly by writing an interface that defines that method and implementing this within each of your user controls. You then cast the object as that interface when attempting to update the controls' property, et voila...

Ryan
Jan 25th, 2005, 12:04 PM
Can you post a link or post some code so I can reference exactly what you're talking about? I'm sorta new to .NET

Magiaus
Jan 26th, 2005, 10:26 AM
I'm not sure I understand the question exactly, but I add a Load method to my UserControls that need to load data. I use LoadControl and then cast to the Control type I need and call the Load Method.

An interface is a great way to do this if the way you load variable info is common though. You could also make your own UserControl Class that inherits from the UserControl class and add the member you need and base your user controls on this class and cast to it.

I think the Iface is a good way to go though. Clean and simple.