开发者

retaining selected value of ASP.NET DropDownList re-built by JavaScript

开发者 https://www.devze.com 2023-03-19 23:20 出处:网络
I converted a 100% ASP.NET driven form to using nearly all AJAX based architecture except that it doesn\'t submit the data using AJAX call, yet.It does a full page postback.And because the button subm

I converted a 100% ASP.NET driven form to using nearly all AJAX based architecture except that it doesn't submit the data using AJAX call, yet. It does a full page postback. And because the button submissions are still tied to so much functionality (it's a global button custom control with multiple buttons), I chose not to convert them over to AJAX yet.

Every piece of data submits fine, except for one use-case. It's a dropdown that is dependent from another dropdown. So now, when the value of dropdown 1 changes by the end user, dropdown 2 gets rebuilt from AJAX calls (JavaScript). Note, dropdown 1's options NEVER change in the life of the application. When the form is submitted after that workflow, we lose the value of dropdown 2. Hopefully this is making sense. If dropdown 1 doesn't change, dropdown 2 still has the same options from when the form was built in the code behind, so the value in the viewstate can be found when it's posted.

Right now, I have a hidden field to keep track of that value that was selected and works fine for now, but is a bit clumsy. Before I did this development, both dropdowns had the AutoPostback attribute turned on. That caused the form to get resubmitted without submitting the form开发者_StackOverflow中文版, just so the dropdowns could get rebuilt.

Is there a better approach to this problem without making the button perform an AJAX call to submit the data?


Values manipulated in JavaScript can't be maintained on postback, because it won't be accessible on the server side. You can put the selected Value in the Hidden Field and then get it from the Hidden Field.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号