posted 1/9/2009 by Vijendra Shakya
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:
<div> <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> </div>
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; pnlText.Controls.Add(txt); } }
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.
What kind of email newsletter would you prefer to receive from CodeAsp.Net?18