Dynamically Loading .NET Custom Controls Using Reflection

The usual way of adding custom controls on a Web Forms page is by specifying the required HTML markup in the Web Page. But in real world applications we may need to dynamically load custom controls. Here is one way of doing so using Reflections.

System.Reflection.Assembly a =
Type t = a.GetType(string.Concat("Myproject.Controls.", "CustomControl1"));

if (null != t)
Control c = ((Control)(Activator.CreateInstance(t)));

// Then we can access the properties of the control by
// casting the it to the relevant type.
((Myproject.Controls.CustomControl1)c).ID = "ctrlCustomControl1";

Visual Studio Projects - Project Type GUIDs

Visual Studio projects have a project type (in some cases more than one type) and it is identified by a unique GUID. This GUID is generally available in the project file. But in projects like Web Site projects which do not have a project file; this GUID is stored in the solution file.

A list of known project type GUIDs are as follows:

Windows (C#)

Windows (VB.NET)

Windows (Visual C++)

Web Application

Web Site

Disdivibuted System

Windows Communication Foundation (WCF)

Windows Presentation Foundation (WPF)

Visual Database Tools


Database (other project types)


Legacy (2003) Smart Device (C#)

Legacy (2003) Smart Device (VB.NET)

Smart Device (C#)

Smart Device (VB.NET)

Workflow (C#)

Workflow (VB.NET)

Deployment Merge Module

Deployment Cab

Deployment Setup

Deployment Smart Device Cab

Visual Studio Tools for Applications (VSTA)

Visual Studio Tools for Office (VSTO)

SharePoint Workflow

XNA (Windows)

XNA (XBox)

XNA (Zune)

SharePoint (VB.NET)

SharePoint (C#)