Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to add textbox on button click one or two at a time on whatever times click on button ...
Posted
Comments
CHill60 20-May-13 8:47am    
What have you tried so far?
Dev Ashish Jangid 20-May-13 8:48am    
Are u looking for add TextBox dynamically on your page....?
Member 9579525 20-May-13 9:03am    
yes..
joshrduncan2012 20-May-13 9:15am    
What have you tried so far to accomplish this? Do you want someone to do the work for you?

1 solution

Below is sample code for you idea. Please refine this code according to your requirement.

C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        ViewState["textBoxCount"] = 0;
    }

}

protected void Button1_Click(object sender, EventArgs e)
{
    int textBoxCount =(int) ViewState["textBoxCount"] ;
    textBoxCount++;
    for (var i = 0; i < textBoxCount; i++)
    {
        TextBox txt = new TextBox();
        Literal lit = new Literal();
        lit.Text = "";

        PlaceHolder1.Controls.Add(txt);
        PlaceHolder1.Controls.Add(lit);
    }
    ViewState["textBoxCount"] = textBoxCount;
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900