简体   繁体   中英

Adding form fields dynamically, then saving them away

I have an asp.net form page used for capturing data for a particular task, the task items will be displayed in a tabular fashion. there may be a number of items included in this task, for which I wish to add the appropriate form fields dynamically. I then will need to 'save' the data from the form.

I was wondering what would be the easiest way to approach this.

I had planned on generating a single 'starter' row and then using jQuery to clone it (whilst renaming the inputs slightly) as I needed. only problem with this is that depending on the types of task items, the form fields would be slightly different. which would mean having a very complex 'starter' row to start with and a fair bit of code in the js along with the cloning - or I guess holding each 'type' of starter rown, hidden somewhere on the page and cloning them into life as necessary

or maybe having a js function for each task type that uses append(...html...)

I was trying to avoid using an updatepanel - in which I could generate all the new fields in the code behind, but maybe that would be simpler?

but along with this, when I actually want to save the data away, presume the only way to get at it all is to use the Request.Form collection?

interested in how you guys would approach this, as trying to not make this hard on myself.

thanks

nat

If you are building the UI using JQuery, why not send the final results back to the server via a web service, called by a JQuery $.ajax command? This way, you wouldn't need to rebuild the UI from client-side code after every postback, which would be the problem with building content client-side, but posting back from every response.

It looks like your form is very dynamic in nature. Creating all these dynamic controls on the server side can become really messy, especially because you have to work with it both on the server and on the client.

An alternative would be to do everything html related on the client and leave only the data processing to the server, using json as the data format.

I just started to work with angular and I am really impressed.

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