views:

12

answers:

1

Hello all. My issue is similar to http://stackoverflow.com/questions/2613627/how-to-use-the-value-of-a-selected-value-from-a-dropdownlist-populated-with-ajax 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  A: 

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).

VinayC
How can I use that to get the value into the SQL data source? It is still posting back null values.
C Bauer
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.
VinayC