2
Answers

creating textbox at runtime

prasanna shah

prasanna shah

13y
2.7k
1
how to create textboxes at runtime on button click. As many time as the button is clicked and the value of textbox is to be passed to next page through session.

i have such code so far
 protected void btnadd_Click(object sender, EventArgs e)
    {
        var i = 1;
        for (i = 1; i <= count+1; i++)
        {
            TextBox txt = new TextBox();
            form1.Controls.Add(txt);
            txt.ID = "r" + count;
            txt.Text = txt.ID;
        }
     }

Here i want to give the ID to all the textbox that will be created at runtime.This code displays textbox only once when the button is clicked. But i want to display textbox everytime when the button is clicked.

If do this
protected void btnadd_Click(object sender, EventArgs e)
    {
        var i = 1;
        for (i = 1; i <= 5; i++)
        {
            TextBox txt = new TextBox();
            form1.Controls.Add(txt);
            txt.ID = "r" + count;
            txt.Text = txt.ID;
            count++;
        }
     }
there displays 5 textbox with id of textbox like ro,r1,r2,r3,r4.


please help me. I have been working on this for many days.
thanks in advance

prasanna
Answers (2)