Load UserControl With Reflection
Categories: UserControls, UserControls Switching
|
Tags: Developers, 1. Beginner, 2. Intermediate, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
Revision:
1
Posted:
18/Nov/2009
Updated:
23/July/2010
Status:
Publish
Types: Article
|
This article will have a few sections added to it soon, based on the following article type skeleton: CodeSample Load UserControl using reflectionThis article explains how to load a UserControl to a Visual WebGui application in run-time from an assembly that is not referenced in your project.The way this is done in .NET is with Reflection. Code samplesC# Code
string strBaseDir = AppDomain.CurrentDomain.BaseDirectory;
string strSlnDir = strBaseDir.Remove(AppDomain.CurrentDomain.BaseDirectory.LastIndexOf(@"\UserControlLoadInRunTime"));
string strPathToAsm = Path.Combine(strBaseDir, @"WebGUIControlLibrary\bin\Debug\WebGUIControlLibrary.dll");
try
{
Assembly objAsm = Assembly.LoadFile(strPathToAsm);
object objTemp = objAsm.CreateInstance("WebGUIControlLibrary.UserControl1");
Gizmox.WebGUI.Forms.UserControl objUserControl = objTemp as Gizmox.WebGUI.Forms.UserControl;
if (objUserControl != null)
{
this.Controls.Add(objUserControl);
}
}
catch(Exception objException)
{
// do something
}
VB.NET Code
Dim strBaseDir As String = AppDomain.CurrentDomain.BaseDirectory
Dim strSlnDir As String = strBaseDir.Remove(AppDomain.CurrentDomain.BaseDirectory.LastIndexOf("\UserControlLoadInRunTime"))
Dim strPathToAsm As String = Path.Combine(strBaseDir, "WebGUIControlLibrary\bin\Debug\WebGUIControlLibrary.dll")
Try
Dim objAsm As Assembly = Assembly.LoadFile(strPathToAsm)
Dim objTemp As Object = objAsm.CreateInstance("WebGUIControlLibrary.UserControl1")
Dim objUserControl As Gizmox.WebGUI.Forms.UserControl = TryCast(objTemp, Gizmox.WebGUI.Forms.UserControl)
If objUserControl IsNot Nothing Then
Me.Controls.Add(objUserControl)
End If
Catch objException As Exception
' do something
End Try
The demo applicationThe demo application is supplied both in C# and VB.NET code for Visual Studio 2005 and 2008 and can be downloaded from here
About the author
Related Articles
|
UserControls
|
|
|
This video demonstrates how to work with user controls.
Tags:
Developers, Drag & Drop, 1. Beginner, 2. Intermediate, 3. Advanced, Customization, Layouting, Pre v6.3, v6.3, v6.4 and Later
|
|
|
This sample application was created on VWG v6.3.x.
The creator of this application suggests that VWG v6.4 would give much greater flexibility.
Tags:
Architects, Developers, Events, Resource Handlers, VB.NET, 2. Intermediate, 3. Advanced, Customization, Layouting, Pre v6.3, v6.3
|
|
|
Tags:
Architects, Developers, Data Binding, 2. Intermediate, 3. Advanced, Data Binding, Pre v6.3, v6.3, v6.4 and Later
|
|
|
This sample code demonstrates working with user controls to simulate frames
Tags:
Developers, Navigation, 1. Beginner, 2. Intermediate, Navigation, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
|
|
|
Tags:
Developers, Navigation, 1. Beginner, 2. Intermediate, Navigation, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
|
|
|
Tags:
Developers, Navigation, 1. Beginner, 2. Intermediate, Navigation, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
|
|
|
|