hello,
sir i need how to generate "text box" dynamically in asp .net on the button click.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sanjeeb LenkaPosted Dec 2, 2013, 1:26 AM
in aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
in .cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
TextBox txt = new TextBox();
txt.ID = "tb";
txt.Width = 540;
txt.Height = 60;
txt.TextMode = TextBoxMode.MultiLine;
form1.Controls.Add(txt);
}
}
Abhay ShankerPosted Dec 2, 2013, 1:55 AM
on aspx page
<asp:TextBox runat="server" ID="textbox1"/>
<asp:TextBox runat="server" ID="textbox2"/>
<asp:Button runat="server" ID="btnAdd" OnClick="btnAdd_Click" />
<asp:PlaceHolder runat="server" ID="ph" />
in Code Page
protected void btnAdd_Click(object sender, EventArgs e)
{
TextBox tb1 = new TextBox();
TextBox tb2 = new TextBox();
ph.Controls.Add(tb1);
ph.Controls.Add(tb2);
}
Also check below link for better understanding
http://www.codeproject.com/Articles/502251/How-to-create-controls-dynamically-in-ASP-NET-and