How to add controls dynamically to ASP.NET form?

后端 未结 6 1757
说谎
说谎 2021-01-12 02:16

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#.

6条回答
  •  清酒与你
    2021-01-12 02:25

    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();
       }
    }
    

提交回复
热议问题