Posted by : Anwar Hossain
Category : How to create asp.net control dynamically

Dynamically TextBox control creation in ASP.Net C #.

Dear viewer’s Sometimes we need to create ASP.Net Textbox programmatically or dynamically. In this tutorial I will show how to create ASP.Net Textbox Control dynamically in ASP.Net C #. For creating ASP.Net Textbox Control I have created a function and called the function page load event. I have used for loop to create multiple Textbox but without using loop one Textbox Control can be created.

Dynamically TextBox control creation in ASP.Net C #.

HTML

<html >

<head runat="server">

    <title>Create textbox dynamically  </title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

   

    </div>

    </form>

</body>

</html>

CODE BEHIND

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Drawing;

 

public partial class createtextbox : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

 

 

        //Create textbox dynamically

 

        CreateTexbox();

    }

    private void CreateTexbox()

    {

 

        //limit to ceate textbox

        int a = 15;

        for (int i = 0; i < a; i++)

        {

            TextBox txtDynamic = new TextBox();

 

            //Declaring the textbox ID name

 

            txtDynamic.ID = "tb" + "" + ViewState["MyText"] + i + "<br/>";

 

            txtDynamic.Width = 400;

            txtDynamic.Height = 20;

 

            txtDynamic.BorderStyle = BorderStyle.Solid;

            txtDynamic.Style["Top"] = "25px";

            txtDynamic.Style["Left"] = "100px";

            txtDynamic.BackColor = Color.DarkGray;

            txtDynamic.BorderColor = Color.Coral;

            txtDynamic.TextMode = TextBoxMode.MultiLine;

 

            form1.Controls.Add(txtDynamic);

        }

 

    }

 

  

}

Out Put

textbox-asp.net



Realted Article Headline

Dynamically Label control creation in ASP.Net C #.
Dynamically TextBox control creation in ASP.Net C #.

Article Category

How to create asp.net control dynamically
Learn HTML for beginner
DataList example in C Sharp
Mail sending in asp.net c#
State Management in ASP C #
Basic sql tutorial for Beginner
DataTable example in ASP.Net C#
How to use LINQ in ASP.NET C#
asp.net c # basic tutorial
How to use ajax toolkit in asp.net C#
How to use different types of validation control using asp.net c#
How to use grid view in asp.net c#
Protected by Copyscape Online Plagiarism Detection