Loading ...

Dynamically Genearte TextBox at runtime in ASP.Net | CodeAsp.Net

Dynamically Genearte TextBox at runtime in ASP.Net

0 (0votes)

Here we discuss to generate the textox at runtime. To create the textbox at run time for that first we take a server control Panel where we place the runtime generated textbox.Here we use a textbox and button,textbox to define the number of textbox generated at runtime ant generate the textbox on the button click.

following is the code for .aspx side:

<asp:TextBox runat="server" ID="txtadd" ></asp:TextBox>
<asp:Button ID="btnAdd" runat="server" Text="Create" onclick="btnAdd_Click" />
<asp:Panel ID="pnlText" runat="server"></asp:Panel>

code for code behind file:

 protected void btnAdd_Click(object sender, EventArgs e)
            for (int i = 0; i < Convert.ToInt32(txtadd.Text); i++)
                TextBox txt = new TextBox();
                txt.Width = 300;
                txt.Height = 50;
                txt.ID = "txtbox" + i;
                txt.TextMode = TextBoxMode.MultiLine;

on the button click we define the properties of the text box which u want for runtime generated textboxes and add these textbox in the panel where we display the textbox.
This is simplay for enter the value in the given textbox and click on the button and then textboxes is display in the panel.



Comments (1)

actually in my page 2 buttons are there if i click first button automatically generate textbox and when ever i click the button generate textbox with different ids .if i click another button it will read the text from all generate textbox

Top Posts