Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Dynamically generate Class Names


Message #1 by "Lou Feicht" <lfeicht@f...> on Fri, 23 Nov 2001 21:52:30
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')
> 

  Return to Index