Hi,
I have an application in which we have button to create textboxes dynamically.
On clicking on button named Addnew ,we get textbox in a table.

The problem is that when the page is refreshed,data entered is vanished.
I want to get data from texboxes on submit click.
Can any one tell me the procedure to get data from dynamically created textboxes.
Waiting for u r reply.

Can u plz tell how u did this..

in design:
--------

<table width="600" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#cccccc">
<tr> 
<td width="100" rowspan="2" align="right" bgcolor="#eeeeee" class="header1"> Web 
Control added Dynamically:</td>
<td align="center" bgcolor="#FFFFFF"> <br /> 
<asp:Panel ID="pnlMain" runat="server" Height="300px" Width="500px">
</asp:Panel>
<br /> &namp;bsp;
</td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">
<asp:button ID="btnSubmit" runat="server" Text="Create Button" OnClick="btnSubmit_Click" />Button
ID:
<asp:TextBox ID="txtID" runat="server" Width="64px"></asp:TextBox>
Button Color:<asp:TextBox ID="txtForeColor" runat="server" Width="64px"></asp:TextBox> <br />
Button Text:<asp:TextBox ID="txtText" runat="server" Width="64px"></asp:TextBox> <br />
<asp:label ID="lblStatus" runat="server"></asp:label> </td>
</tr>
</table>

in code:
-----------

static Button[] btn_arr = new Button[20];
    static int btn_count;

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (btn_arr[0] is Button)
            {
                //for each button saved in our array, recreate it
                foreach (Button button in btn_arr)
                {
                    add_button(button);
                }
            }
        }
        catch (Exception ex)
        {
            lblStatus.Text += ex.Message.ToString();
        }
    }

    protected void add_button(Button button)
    {
        try
        {
            //add to a container on the page
            pnlMain.Controls.Add(button);
            //add a spacer after the control
            pnlMain.Controls.Add(new LiteralControl("<br>"));
        }
        catch (Exception ex)
        {
            lblStatus.Text += ex.Message.ToString();
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            //create a new instance of the control
            Button new_button = new Button();
            new_button.ID = txtID.Text;
            new_button.ForeColor = System.Drawing.Color.FromName(txtForeColor.Text);
            new_button.Text = txtText.Text;
            //add button to button array
            btn_arr[btn_count++] = new_button;
            //call our add function
            add_button(new_button);
            lblStatus.Text += "Created button " + new_button.ID + " and of color " + new_button.ForeColor;
        }
        catch (Exception ex)
        {
            lblStatus.Text += ex.Message.ToString();
        }
    }

hope this helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.