I have a web page where I use jQuery AJAX to load data from a database to fill a drop down list. When the jQuery function runs, the server events does not fire.
jQuery:
$('#Cmb_PDept').on('change', function (e) {
e.preventDefault();
var DepartmentId = $('#Cmb_PDept :selected').val();
if (DepartmentId == 0) {
EmpCombo.empty();
textbox.val("");
return;
}
$.ajax({
type: "POST",
cache: false,
contentType: "application/json; charset=utf-8",
url: '/WebService/GetEmployeeByDepID.asmx/GetEmployee',
data: '{ "DepartmentId": "' + DepartmentId + '" }',
dataType: 'json',
success: function (data) {
var data = $.parseJSON(data.d)
var options = $("#Cmb_PEmp");
options.empty();
for (var i = 0; i < data.length ; i++) {
options.append("<option value='" + data[i]["EmployeeId"] + "'>" + data[i]["EmployeeName"] + "</option>");
}
myEvent();
},
error: function () { alert("error"); }
});
});
ASP.NET Button
control
<asp:Button ID="Btn_PIncrementSave" runat="server" Text="Save"
OnClick="Btn_PIncrementSave_Click" CausesValidation="false" />
The onClick
event
protected void Btn_PIncrementSave_Click(object sender, EventArgs e)
{
try
{
TxBx_IncrementAmount.Text = Hid_BasicSalary.Value;
}
catch (Exception ex)
{
Utility.Msg_Error(this.Master, ex.Message);
}
}
This event does not fire. I think this is due to
e.preventDefault();
When I remove this, the server-side event works properly.