Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
please explain briefly....thank you
Posted

We create dynamically the controls whenever we don't know in advance what controls we actually need (for instance if they depend on user's choice or are configured externally, e.g. in a database). Once dynamically created, such controls are handled exactly like the statically created ones.
 
Share this answer
 
The main reason would be when you do not know how many controls you need at design time.
Here are some Golden rules[^] to remember when working with dynamic controls.
 
Share this answer
 
Loads of reasons.
As Carlo has said, we create them because we don't know what we need at design time.

This may be because the data comes from a DB and we don't know how much there is of it.
Or it could be because the user is an Admin and gets more advanced controls than a standard user.

We may also create controls at run time because the user is loading a "template form" which describes what the display should look like in an external file.

But in truth, in C# all controls are created dynamically - even those you "fix in place" on a Winforms app with the Visual Studio designer. The code which displays controls is in the myfilename.Designer.cs (for Winforms) file or the myfilename.aspx file (for websites), and you can examine it freely if you want to see how VS does it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900