I couldn't get your code to work but was able to do what I wanted by using
system.reflection and instantiating my assembly.
Although i'm not sure what i'm doing is best in terms of performance.
> Lou,
>
> OK, I think I understanding what you are trying to
> do now. The Type class will probably do 90% of what
> you want:
>
> Dim myControlType As Type
> Dim myControl As Object
>
> myControlType = Type.GetType("MyProject." &
> objDataReader("QuestionName"))
> myControl = Type.CreateInstance(myControlType)
>
> You ever be able to invoke the instance using its
> actual interface, but you could cast it to a super
> class and work with it that way.
>
> It just depends on what the parentage of your controls
> are, anyway, I hope this helps.
>
> ----------------------------------------
> - Mitch Denny
> - http://www.warbyte.com
> - mitch.denny@w...
> - +61 (414) 610-141
> -
>
> > -----Original Message-----
> > From: Lou Feicht [mailto:lfeicht@f...]
> > Sent: Thursday, 29 November 2001 11:07 PM
> > To: ASPX_Professional
> > Subject: [aspx_professional] RE: Dynamically generate Class Names
> >
> >
> > I'm doing a sql query to dynamically populate a form on a page with
> > questions. The questions are User Controls (i'm not sure if
> > that's the
> > correct terminology). They are vb classes.
> > The sql query determines which controls I want to put on the
> > page, this is
> > based upon the the page name and user security level.
> >
> > So the sql could look like "Select QuestionName, QuestionID From
> > QuestionTable Where PageName='BottomFeeders' and SecLevel <=20"
> >
> > Then I am dynamically building a table and loading the controls using
> > LoadControl.
> >
> > I have a workaround doing a Select case. eg
> >
> > Select objDataReader("QuestionName")
> > Case "Customer"
> > ..LoadControl("MyProject.Customer")
> >
> > I was looking for a better solution without having to use a
> > Select/Case/switch statement which requires code changes if I
> > add more
> > User Control classes.
> >
> > So instead of the Select I'd like to do:
> >
> > objClassName="MyProject." & objDataReader("QuestionName")
> > Dim myControl As objClassName
> >
> > I was looking into the Activator, Factory and Reflection
> > namespaces but
> > haven't solved the problem yet.
> >
> >
> >
> >
> >
> >
> > > Lou,
> > >
> > > You can implement something like this using the "reflection"
> > > capabilities of .NET, although the usage won't be as clean
> > > as the usage you've indicated below.
> > >
> > > Using reflection, you can dynamically create types in memory
> > > and instansite them. Note however that there is a performance
> > > impact involved in this and it can get quite complicated
> > > depending on what you need to do based on the data you pull
> > > from the database.
> > >
> > > This approach is quite involved so its not possible to
> > > cover everything you need to do in this one post. As a starting
> > > point I'd recommend that you take a look at the System.Reflection
> > > namespace in the .NET Framework SDK documentation.
> > >
> > > If you are still interested, post more specific details
> > > about you are wanting to do and we can help you work
> > > through the problem.
> > >
> > > ----------------------------------------
> > > - Mitch Denny
> > > - http://www.warbyte.com
> > > - mitch.denny@w...
> > > - +61 (414) 610-141
> > > -
> > >
> > > > -----Original Message-----
> > > > From: Lou Feicht [mailto:lfeicht@f...]
> > > > Sent: Friday, 23 November 2001 9:53 PM
> > > > To: ASPX_Professional
> > > > Subject: [aspx_professional] Dynamically generate Class Names
> > > >
> > > >
> > > > Is it possible to dynamically generate a Class name and then to
> > > > instantiate on object from the name.
> > > >
> > > > I want to do something link
> > > >
> > > > DIM NewUserControl As (the name which comes from the data base).
> > > >
> > > > I won't know if I want to create the NewUserControl until
> > i read the
> > > > results from the query.
> > > > ---
> > > > VBug Winter Conference 2001
> > > >
> > > > Make no mistake - there's a great learning curve
> > > > for developers moving from COM to .NET. So why
> > > > would you want to be a pioneer and cross the bridges
> > > > first? Attend the .NET Developer's Conference
> > > > (28th to 30th November 2001) In London and realise
> > > > the benefits of adopting the technology early. By
> > > > attending you'll understand the key challenges and
> > > > be left with a thorough understanding of the major
> > > > .NET fundamentals. If you're already working
> > > > with .NET this is a must-attend event.
> > > >
> > > http://www.vbug.co.uk/redirect.asp?url=39&id=17
> > >
> > > ---
> > > You are currently subscribed to
> > > aspx_professional as: mitch.denny@w...
> > > $subst('Email.Unsub')
> > >
> >
> > ---
> > VBug Winter Conference 2001
> >
> > Make no mistake - there's a great learning curve
> > for developers moving from COM to .NET. So why
> > would you want to be a pioneer and cross the bridges
> > first? Attend the .NET Developer's Conference
> > (28th to 30th November 2001) In London and realise
> > the benefits of adopting the technology early. By
> > attending you'll understand the key challenges and
> > be left with a thorough understanding of the major
> > .NET fundamentals. If you're already working
> > with .NET this is a must-attend event.
> >
> http://www.vbug.co.uk/redirect.asp?url=39&id=17
>
> ---
> You are currently subscribed to
> aspx_professional as: mitch.denny@w...
> $subst('Email.Unsub')
> Read the future with ebooks at B&N
> http://service.bfast.com/bfast/click?bfmid=2181&sourceid=38934667&catego
> ryid=rn_ebooks
>