Mink Machine

Dynamic type creation in ASP.NET

ASP.NET web controls are usually littered in the markup in design time, but sometimes there is a need to dynamically add controls to an ASP.NET web page in runtime. Its quite easy to generate a server control from a string. The built-in types are stored in the GAC and requires a fully qualified strong name, such as:

“System.Web.UI.WebControls.Button, System.Web, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”;

This information can be found at c:\windows\assembly where you can view the properties of the assemblies. Once you got the strong name, the control can be created and eventually added to the controls collection of another control.

string s = “System.Web.UI.WebControls.Button, System.Web,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”;
Type t = Type.GetType(s);
Control c = (Control)Activator.CreateInstance(t);
f.Controls.Add(c);

Comments

No comments yet.

Post a comment

Your email address will not be published. Required fields are marked *

Featured stories

Chilling in Chile

Chilling in Chile

"My weary feet has reached Valparaiso. After almost a month of traveling across the South American continent I realize that this is as far south as I will come, due to weather conditions."
The urban maze of Tangier

The urban maze of Tangier

"There are exciting things waiting around every corner and my bucket list is long, but the Medina has a mindset of its own regarding time and space."
Reliving history in Washington D.C.

Reliving history in Washington D.C.

"As I entered the heavily guarded Rotunda in the center, some of the most famous documents in the world laid before me."
Vineyards of southern France

Vineyards of southern France

"Not far from Sauternes is the village of Saint-Émilion, also a famous wine region but what got me hooked was their impressive limestone caves."
The dark days of Sarajevo

The dark days of Sarajevo

"The city survived on the edge of annihilation and has started to recover, but the stone walls still seem to cry out in lament of all the horrible things they have seen."
The sound of Salzburg

The sound of Salzburg

"It is based on the true story of Maria von Trapp, even though I suspect she didn’t go singing alone in the mountain ranges."

Instagram

Seville
Venice
Fever Ray
Rome
Basel
Kuala Lumpur