Encountering an issue where I need to remove HTML controls that were added client-side using JavaScript after a postback caused by server-side validation (which is non-negotiable).
Please advise if my current method is subpar and suggest a more effective approach.
Essentially, what I'm doing is duplicating a textbox control up to 10 times on the page when the user clicks "Add," then storing the entered values from each of those textboxes in a hidden field for retrieval in the code behind. This setup works well, but when server-side validation fails after the postback, all dynamically added (cloned) textboxes disappear because ViewState doesn't recognize them.
I am considering two potential solutions, both of which seem makeshift:
Recreate all cloned textboxes on document onload() using stored values in the hidden field
Encase the form in an AJAX update panel and position the cloned textboxes outside of it to prevent this area of the screen from refreshing during postback
Is there a way to somehow "update" ViewState to acknowledge all the HTML controls added via client-side script? Any better suggestions? I prefer accomplishing this with client-side scripting and therefore not interested in cloning textboxes on the server side, sorry.