How to add label dynamically in asp.net

{0 Comments}

Adding a label in asp.net dynamically is very easy, as we know that label is a type of control which on run time creates a span with same id which you assign to label. So we can create label control dynamically in the similar manner in which other controls are created, which is as follows, the thing which you should keep in mind is to add this control to form or panel, otherwise it will throw a error, the syntax is as follows:

 C# |  copy code |? 
1
Label lb = new Label();
2
        lb.ID = "akv";
3
        lb.Text = "your dynamic text";
4
        form1.Controls.Add(lb);

Leave a Comment

Your email address will not be published.