Results 1 to 4 of 4

Thread: Possible?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    California
    Posts
    115

    Possible?

    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:

    Code:
    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?

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    Re: Possible?

    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...

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    California
    Posts
    115

    Re: Possible?

    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

  4. #4
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: Possible?

    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.
    Magiaus

    If I helped give me some points.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width