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#.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Carriage Return (ASCII chr 13) is missing from tex
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
In Aspx
U can use the following in the Cs file to laod the control dynamically...
or try this
Can also have a look at:
http://aspalliance.com/565
http://samuelmueller.com/2008/12/dynamicloader-plugin-dynamically-loading-asp-net-user-controls-with-jquery
http://forums.asp.net/p/1222567/2826338.aspx
Please see the below sample
lets say forms name is frmMain.
Below is the code to add controls dynamically to ASP.NET form.
Add the label object to the panel.
Label lbl1 = new Label();
lbl1.Text = "Your message here";
Panel panel1= new Panel();
panel1.Controls.Add(lbl1);
In the form, the following code can add a button dynamically:
It's generally acceptable to add the controls to a panel, be it that the panel has been added to the page in the markup or programmatically.
See the following link for the C# syntax
Below is the code that can be called on some events like page load or onload or even some user action like onclick.