简体   繁体   中英

How do I dynamically add controls to C# forms and read values in codebehind?

I wonder if someone can help

I have a ASP.NET form and by clicking a button on the page user should be able to add new dynamic controls to it. the button click should be add one dropdown and two textboxes like append to a DIV or to panel.

However then on click of another button I would like to read values of all the three controls on the backend.

How can this be done, thanks in advance.

You can look at the classes in the System.Web.UI.WebControls Namespace to get a full list of options for dynamically creating and reading controls in .net / c#. Here's a quick example from MS that covers the how-to.

To read the controls you create, make sure you create them with a strong ID or class such as "CustomerFirstName" or "Address2" so that you can access them easily. You also have control over the parent so you can access a parent control and then loop through each child and access data in each

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM