.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 >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Dynamically create textbox in ASP.NEt

Posted By:Athira Sreejith       Posted Date: March 25, 2009    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  
 

Below code demonstrate how to create textbox dynamically in asp.net

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);
            }
        }
    }
}


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

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