TextBox tb=new TextBox(); Panel1.Controls.Add(tb);
private System.Windows.Forms.TextBox[] textboxes; textboxes = new System.Windows.Forms.TextBox[2]; int cnt=0; foreach (System.Windows.Forms.TextBox textbox in textboxes) { // the location on the form. you may need to play with this // and it should change for each textbox textbox.Location = new System.Drawing.Point(88, 50); textbox.Name = "textbox"+cnt.ToString(); textbox.Size = new System.Drawing.Size(173, 20); textbox.TabIndex = cnt; textbox.Visible = true; cnt++; }
vijaya
<table> <tr> <td> Program Interested </td> <td> <asp:TextBox ID="txtprogram" runat="server" CssClass="txtbox"></asp:TextBox> </td> <td> <asp:ImageButton ID="img1" runat="server" ImageUrl="~/images/btn_add.gif" onclick="img1_Click" /> <asp:Panel ID="p1" runat="server"></asp:Panel></td></tr> </table>
textbox tb=new textbox(); literal1.controls.add(tb); or placeholder1.controls.add(tb);
Thanks&Regards LakshmiNarayana Nalluri.
ASPX <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Add Textbox" /> <asp:Panel ID="Panel1" runat="server" > </asp:Panel> </div> </form> </body> </html>
using System; using System.Web.UI.WebControls; using System.Collections.Generic; namespace WebApplication1 { public partial class _Default : System.Web.UI.Page { private List textboxes; protected void Page_Load(object sender, EventArgs e) { PreRender += new EventHandler(_Default_PreRender); textboxes = new List(); if(IsPostBack) { //recreate Textboxes int count = Int32.Parse(ViewState["tbCount"].ToString()); for (int i = 0; i < count; i++) { TextBox tb = new TextBox(); tb.ID = "tb" + i; Panel1.Controls.Add(tb); textboxes.Add(tb); tb.Text = Request.Form[tb.ClientID]; } } } protected void Button1_Click(object sender, EventArgs e) { //create new textbox TextBox tb = new TextBox(); tb.ID = "tb" + textboxes.Count; Panel1.Controls.Add(tb); textboxes.Add(tb); } void _Default_PreRender(object sender, EventArgs e) { //remember how many textboxes we had ViewState["tbCount"] = textboxes.Count; } } }
Regards, Susan
Login to post response