0

My issue is similar to How to use the Value of a Selected Value from a DropDownList populated with AJAX/PHP but I am using ASP.NET, not PHP.

I have a dropdownlist that is populated by another dropdownlist's current value through ajax. So if DDL A is 'NY', DDL B is populated with different data relating to 'NY'. I need that data to be posted back to the server because this affects an SQLDataSource parameter. However, as far as I can tell, the value is always null after postback resulting in the gridview to be empty.

How can I force ASP to read the dropdownlist's current value?

1 Answer 1

1

DDL B is populated at client side - there are no elements present in it on server side. That's why on server side, you will not get any value out of control. However, you can always lookup in the request post data - Request.Form[DDLB.UniqueID] to get the selected drop-down value.

Edit: typically, you need to turn page event validation off in scenarios where your server control may post back invalid value (for example, a drop down returning value not present in its options).

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

2 Comments

How can I use that to get the value into the SQL data source? It is still posting back null values.
Does Request.Form[DDLB.UniqueID] return null? If yes, check what is the "name" attribute for DDL B in your page source, your request should have selected value with name as key. If you can get the data then you can pass it to SQL data source programmatically.

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.