I created a table of form fields with ASP.net and the repeater control which contains data from a database.
Now the user can add rows which will add a new row with jQuery to the repeater control (which is a html table when it’s rendered. So I’m adding these rows to the client side html table and not to the repeaters data source).
When the user is posting the data to the server I’m able to access the edited rows directly from the repeater but of course, the new jQuery generated rows aren’t stored in the repeater.
I also took a look at the Request.Form variables, but there are just the repeater controls too (If I’m wrong with my assumption that this should be that way, please give me some sign).
The only one solution I see is to store all rows data in a json object and pass it to the server. But it would be great if there is another solution without using Javascript to post the data.
What’s the best way to solve this problem?
Ok, I have to say: it’s possible just by accessing the Form.Request Data. It’s important, when you’re generating new fields on client side, you have to set new and different name attribute values for all the form fields because Request.Form contains the fields values grouped by the name values. And if you’re generating new rows like I do with a clone() of another row, they would be identically and you can’t see them in the Request.Form if you don’t change them.
Another solution is to save all the form data in a JSON object and at it to a hidden field. Server side you can easy deserialize the JSON Object (maybe you need a JSON library first) and access your data. There’s no need for a AJAX request.
I would say, the best way is JSON Object way. I did it with the Request.Form to write less Javscript and more server-side script.