Posted by : Anwar Hossain
Category : How to create control dynamically

Dynamically Label control creation in ASP.Net C #.

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

Dynamically Label control creation in ASP.Net C #.



<head runat="server">

    <title>Create Label dynamically  </title>



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









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 LabelControl : System.Web.UI.Page


    protected void Page_Load(object sender, EventArgs e)



        //Create Label dynamically




    private void CreataLabel()



        //limit to Label textbox

        int a = 15;

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


            Label lblDynamic = new Label();


            //Declaring the textbox ID name


            lblDynamic.ID = "lbl" + "" + ViewState["MyLebel"] + i + "<br/>";


            lblDynamic.Width = 400;

            lblDynamic.Height = 20;

            lblDynamic.Text = "Label" + "&nbsp;" + i + "<br/>";


            lblDynamic.BorderStyle = BorderStyle.Solid;

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

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

            lblDynamic.BackColor = Color.DarkKhaki;

            lblDynamic.BorderColor = Color.DarkOliveGreen;











Out Put


Realted Article Headline

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

Article Category

How to create control dynamically
Learn HTML for beginner
DataList example in C Sharp
Mail sending in 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# c # basic tutorial
How to use ajax toolkit in C#
How to use different types of validation control using c#
How to use grid view in c#
Protected by Copyscape Online Plagiarism Detection