How to get dropdown selecteditem value on server side when I created client side option

my javascript code

$().ready(function () { $.ajax({ type: "POST", url: "../WebService.asmx/GetDistricts", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { BindDist(msg.d); } }); }); 

a

 function BindDist(msg) { $.each(msg, function () { $("#dropDist").append($("<option></option>").val(this['DistrictId']).html(this['Name'])); }); } 

on the server side, I want to get the value of dropDist.selectedItem.but, I can not get the value of how to do this.

 int DistrictId = Int32.Parse((dropDist.SelectedValue).ToString()); 

how do i get the dropdown selected value on server side? Any help is greatly appreciated.

+2
source share
1 answer

You cannot get the selected value from the drop-down list if you add options to javascript. In addition, you have lost the SelectedIndexChanged event handler. If you need to populate the drop-down list on the client and still be able to use the SelectedValue property and the SelectedIndexChanged event, you need to develop your own ajax server server. Or you can use some, like ComboBox, from the AjaxControlToolkit library.

Despite all of the above, if you still want to use the usual DropDown populated on the client, then you can get the selected value on the server, as there: string dropDistSelectedValue = Request.Form[dropDist.UniqueID];

+6
source

All Articles