.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Add TextBox dynamically

Posted By: shyjuu     Posted Date: October 03, 2008    Points:2   Category :ASP.Net
Hi friends I want to add textbox dynamically at button click
please tell me the c# code

Responses
Author: Amit Mehra             
Posted Date: October 03, 2008     Points: 5   

Hi,
Just Drag and drop PlaceHolder control in your Web Page and the on button click write this line of code to create 5 textbox on button click


protected void Button1_Click(object sender, EventArgs e)
{
for(int count=0 ;count<5;count++)
{
TextBox txtBox = new TextBox();
txtBox.ID = "txtBox" + count;
this.PlaceHolder1.Controls.Add(txtBox);
}
}


Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: Athira Sreejith             
Posted Date: April 01, 2009     Points: 5   

Hi..

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class DynamicTextbox2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
int n = Int32.Parse(txtTBCount.Text);
for (int i = 0; i < n; i++)
{
// TextBoxesHere.Controls.Add(new CheckBox());
//controls.Controls.Add(new TextBox());
Page.Form.Controls.Add(new TextBox());
}
//IterateThroughChildren(this);
}
public void IterateThroughChildren(Control parent)
{
foreach (Control c in parent.Controls)
{
if (c.GetType().ToString().Equals("System.Web.UI.WebControls.CheckBox") && c.ID == null)
{
}
if (c.Controls.Count > 0)
{
IterateThroughChildren(c);
}
}
}
}



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend