|
-
Sep 12th, 2007, 12:18 PM
#1
[RESOLVED] [2005] .NET equivalent of COM's CreateObject
How do you create an object instance if all you have is the name of the class?
I want to add controls (derived from webcontrols) onto a webpage at runtime. Information is stored in a database, so all I know is the class name of the control, ie
Code:
Public Class wssList
Inherits System.Web.UI.WebControls.BulletedList
Public Sub New()
Me.Items.Add("Test 1")
Me.Items.Add("Test 2")
End Sub
End Class
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ctl As System.Web.UI.Control
Dim str as String = "wssList"
ctl = New ?????????
Me.Forms.Controls.Add(ctl)
End Sub
Last edited by brucevde; Sep 12th, 2007 at 03:51 PM.
-
Sep 12th, 2007, 12:22 PM
#2
Re: [2005] .NET equivalent of COM's CreateObject
Take a look at Activator.CreateInstance method.... Frankly speaking, I've never had the need to use it, so I can't guide you any further.
-
Sep 12th, 2007, 12:31 PM
#3
Re: [2005] .NET equivalent of COM's CreateObject
I've only ever used .CreateInstance with Office. I would think if you have a COM web controls you would instanciate them using the New keyword as long as you have a reference set to the dll.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 12th, 2007, 02:52 PM
#4
Re: [2005] .NET equivalent of COM's CreateObject
I found a couple ways of creating the instance and there are probably more. I am not sure which is the better code to use or if it even makes a difference. I will probably use the ObjectHandle method as it would allow me to package the controls in a different Assembly...
Thanks for the help. Here is the code if anyone else has the same question...
Code:
Dim handle As System.Runtime.Remoting.ObjectHandle
Dim ctl As System.Web.UI.WebControls.WebControl
handle = System.Activator.CreateInstance(Nothing, "wssList")
ctl = handle.Unwrap
Controls.Add(ctl)
Dim oType As System.Type
Dim ctl As System.Web.UI.WebControls.WebControl
oType = Type.GetType("wssList", True, True)
ctl = System.Activator.CreateInstance(oType)
Controls.Add(ctl)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|