Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add controls dynamically to ASP.NET form?

I do not know how to add controls dynamically to the form using C# .net. Can anyone help me? I know this with vb.net but I need to know the syntax in C#.

like image 891
SunilRaj Avatar asked Jan 06 '11 06:01

SunilRaj


1 Answers

Below is the code to add controls dynamically to ASP.NET form.

  1. Initialize a label
  2. Assign text to it.
  3. Initialize a panel
  4. Add the label object to the panel.
     Label lbl1 = new Label();
     lbl1.Text = "Your message here";
     Panel panel1= new Panel();
     panel1.Controls.Add(lbl1);
like image 186
Billy Samuel Avatar answered Sep 27 '22 17:09

Billy Samuel