Wednesday, June 16, 2010

How to create a control using string text -

This article demonstrate how to create a control and add it to the controls collection based on string text value.
Please note the original reference form forums

<%@ Page Language="C#" %>
<html xmlns="" >
<head id="Head1" runat="server">
    <script runat="server">
        protected void Button1_Click(object sender, EventArgs e)
            string controlName = TextBox1.Text;
            string systemweblib = @"C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Web.dll";
            System.Reflection.Assembly ass = System.Reflection.Assembly.LoadFile(systemweblib);
            Type type = ass.GetType("System.Web.UI.WebControls." + controlName);
            Control c = (Control)Activator.CreateInstance(type);
    <form id="form1" runat="server">
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Create Control" 
            onclick="Button1_Click" />
        <asp:Panel ID="Panel1" runat="server">


.NET Development said...

Great job. Because i'm a newbie in this area this topic was the most useful for me.

Joshua Smith said...

Thank you for saying about useful info. It necessary to know that iphone app development could help in your industry by installing customized software products.

Amethyst Walton said...

Good to see the example of related ASP .NET.example is the way of learning and understanding of each thing than the content.

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...