I’m using C# with .NET 4 (though as per company policy, we never use any ASP controls, only HTML inputs, so our pages aren’t really all that much different from Rails or PHP pages).
My page is required to make a number of AJAX requests to populate a few <select>‘s based on the values in other inputs on the form. The AJAX requests merely go to simple ASPX pages that return <option>‘s that are retrieved from a database. When the user submits the form and it goes through some validation, and fails, I want to still retain the values in their inputs. What I am currently doing in my page_load function is storing all of the POST Request’s form values in an object and then re-selecting them on the page. Problem is, I have to re-run all my AJAX requests when the page loads so that I can populate the <select>‘s in order to re-select what the user had submitted at the post.
It’s undesirable to make so many AJAX requests as soon as the page reloads after a POST. Is there a better way I can save all the <option>‘s so that I don’t have to make all these AJAX calls after the page reloads?
How about saving the option values in a hidden input before posting so if the posted form doesnt pass server-side validation you will be able to have the option data in the Request.Form object and you will be able to re-populate the control on the server with these values and use some kind of if() condition to prevent AJAX functions being used on the returned page.