0

I don't currently use ajax.net though I would be open to it if it is the only solution. I have a auto-complete control on screen that I am using to populate a asp.net dropdownlist with values through javascript (jQuery). I have had to use EnableEventValidation="false" to allow this. After I add my options to the select and the form is posted back I would like to be able to get all the values for the option elements I have added to the asp.net dropdownlist through javascript.. Is there a good way to accomplish this?

2 Answers 2

3

If a DropDownList leaves the server with no options, it's recreated server-side with no options (from the viewstate)

You could add the options to a hidden html control as a delimited string in your javascript as well as to the select list. Then iterate that into the control once server-side on post-back. Otherwise you could ajax them to the server and re-render the DropDownList only for each addition.

Sign up to request clarification or add additional context in comments.

1 Comment

I've tried a bunch of things, and without using ASP.NET's "Ajax" library, I think HollyStyles' solution is the only one available. I feel your pain though.
1

You can get the selected value directly from the form like so:

string fooBar = Request.Form[SomeDropDown.UniqueID];

This will return the correct value no matter what you do to to the drop down options. I use javascript to change the quantity dropdown for a product based on size selection for reflecting product availability.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.