Karatas, FERHAT
I would love to change the world, but they won't give me the source code!
HOW TO: Dynamically Create Controls in ASP.NET
24.9.2008 10:07:17 - Filed under : Asp.net
This article demonstrates how to dynamically create/handle a control for an .aspx page.

<form id="form1" runat="server">
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
            <asp:Label ID="Label1" runat="server"></asp:Label><br />
            <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
            <br />
            <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Read" />

        protected void Page_Load(object sender, EventArgs e)

        void CreateTextBox(int Total)
            for (int i = 0; i < Total; i++)
                TextBox TextBox1 = new TextBox();
                TextBox1.ID = "TextBox1" + i.ToString();
                TextBox1.TextChanged += new EventHandler(TextBox_TextChanged);

        void TextBox_TextChanged(object sender, EventArgs e)
            TextBox txtBoxSender = (TextBox)sender;
            Label1.Text += txtBoxSender.Text +"-";

        protected void Button2_Click(object sender, EventArgs e)
            // Todo : other operation

Another example : http://support.microsoft.com/kb/317794

Keywords : Create and handle dynamic controls.
with 0 comments

What do you think ?
Security Code 4502
Check S. Code
Home Page