I have a Checkbox and a Dropdownlist (with a 'All' as first element) like so :
<td style="width: 15px">
<asp:CheckBox ID="isAdvertiserFilter" runat="server" AutoPostBack="false"/>
</td>
<td style="width: 330px">
<asp:DropDownList ID="AdvertiserFilterList" runat="server" DataTextField="Name" DataValueField="Id" AutoPostBack="true" Enabled="false"/>
</td>
The checkbox enable/disable the dropdownlist.
When enabled, the user can select any item in the list (All, Item1, Item2...) The event is handled in the code behind :
this.AdvertiserFilterList.SelectedIndexChanged += new EventHandler(SearchFilter);
So, when the user Uncheck the checkbox I want the dropdownlist to be set to 'All' and be disabled. In my javascript when I set to "All" (value -1, index 0) It doesn't trigger the event of the code behind to call my SearchFilter function.
$(document).on({
click: function (event) {
if ($(event.target).is('#isAdvertiserFilter'))
{
// Enable or disable the dropdowlist
$('select[id*="AdvertiserFilterList"]').attr("disabled", !$('input[id*="isAdvertiserFilter"]').prop("checked"));
// When UNcheck
if (!$('input[id*="isAdvertiserFilter"]').prop("checked")) {
// Set to the dropdownlist to All
$('select[id*="AdvertiserFilterList"]').val("-1");
// Trying to fire the event
$('select[id*="AdvertiserFilterList"]').trigger("change");
}
}
},
});
How to call my codebehind or trigger the event as if the user did it ?
I want to PostBack only when the checkbox is UNcheck (and not check) or when the dropdowlist 'SelectIndexChanged'