1

What's the best way to handle data entered through dynamically generated controls in ASP.NET?

Currently, I have a group of controls that are generated in the Page_Load stage, and I need to access the data from them. It seems like it might be possible to just use a hidden field that's read and parsed on postback, but I'd like to know if there's a better way to do it that makes better use of the framework.

1
  • Why don't you use ASP.NET MVC instead? Commented Dec 31, 2008 at 19:36

3 Answers 3

3

The key is recreating the controls on postback.

Old but good article to explain how and why.

You can also use the request.form collection to grab the posted values.

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

1 Comment

The short version of this is that Page_Load is too late in the game to create the controls: do it in Page_Init instead.
1

redsquare is right. If you can just remember that ASP.Net is a lie wrapped around Http then you will be ok. The browser doesn't really care that MS neatly abstracts the Http Request/Response away from you in the form of Web Controls. It only knows that it needs to wrap up each of the form variables and their respective values and send them back to the server via Http.

Comments

0

You want to keep the dynamic controls created to a minimum, ESPECIALLY if you are attaching events to them.

I am with @redsquare on the ASP.NET MVC recommendation.

Comments

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.