0

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.

3
  • 1
    Do you have any code that you can post? Commented Apr 9, 2015 at 1:02
  • yes, this can be done Commented Apr 9, 2015 at 1:36
  • reworded title to be a question Commented Apr 9, 2015 at 4:10

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

3 Comments

the controls are lost in a postback event, any way to retain them.
The easiest way I can think of is to have a function called when the submit/post button is clicked that will read the controls on the page (either by reading by class or by storing the ID in an array for the session and querying those back) and then at the end of that function (and after validation/error handling) triggering the post from the code-behind rather than the asp form.
If you're using code behind, functions called from things like a button click will allow you to work with the code as soon as the function is called. .Net should take care of the how part of it, you just have to call the function and then work with the data. You can then choose to route it to a redirect to another form, a field update, a database push, etc. Here's a StackOverflow article on how to use a link button to call a function in code behind.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.