Monday, January 21, 2013

How to add dynamic controls in ASP.NET


Below code will add a dynamic TextBox to the "form1" in webpage,  with the id "txtName".

protected void Page_Load(object sender, EventArgs e)
{

if (!Page.IsPostBack)
{
TextBox tx = new TextBox();
tx.ID = "txtName";
form1.Controls.Add(tx);
}
}

No comments:
Write comments
Recommended Posts × +