Im using jquery ajax to fill the dropdownlist.Every thing works fine,but when i click the submit button, the filled dropdownlist gets cleared and nothing is showing.
What could be the problem ?
The code i've written is given below
$("#locationList").change(function () {
FillCashSafe();
})
function FillCashSafe() {
$("#CashSafeLists").empty();
var locationNo = document.getElementById('<%=locationList.ClientID%>').value;
$.ajax({
url: "HealthReport.aspx/GetCashsafes",
data: '{Location: "' + locationNo+ '"}',
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
var optionhtml = '<option value="-1">Select One</option>';
if (data) {
$("#CashSafeLists").append(optionhtml)
$("#CashSafeLists").trigger("liszt:updated");
$.each(data.d, function (key, value) {
$("#CashSafeLists").append($("<option></option>").val(value.CashsafeId).html(value.CashsafeSerialNo));
$("#CashSafeLists").trigger("liszt:updated");
});
}
else {
$("#CashSafeLists").append(optionhtml)
$("#CashSafeLists").trigger("liszt:updated");
}
},
error: function (result) {
$("#CashSafeLists").append($("<option></option>").val("-1").html("Select one"));
$("#CashSafeLists").trigger("liszt:updated");
}
});
The button click is as follows
<input type="submit" id="Submit1" name="btnSearch" value="Search"
class="btn btn-primary btn-Addbutton " style="margin-left: 4px;" runat="server"
onserverclick="SearchButtonClicked" />