How to add controls dynamically to the form using C#.NET?

 Posted by Tripati_tutu on 12/21/2010 | Category: C# Interview questions | Views: 3864 | Points: 40
Answer:

Below is the code that can be called on some events like page load or onload or even some user action like onclick.

protected void add_button(Button btn)

{
try
{
panel1.Controls.Add(btn); // Add the control to the container on a page
}
catch (Exception ee)
{
lblError.Text = ee.Message.ToString();
}
}


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response