I am showing a loading image onclick of any of the item in the CheckBoxList
.I am using javascript onclick
method.
CheckBoxList control
<asp:CheckBoxList ID="ckBLBusinessUnits" onclick="loader(this.id);" runat="server" AutoPostBack="True" Visible="false" OnSelectedIndexChanged="ckBLBusinessUnits_SelectedIndexChanged"></asp:CheckBoxList>
I am forced to use JS onclick
instead of jQuery event binding, as the control is inside the updatepanel. The jQuery function is not firing after the initial load. If i add an alternative .ie to use Sys.Application.add_load(loader);
then the server side code is executed first and later the JS function. Which doesn't help my case.
JS function
function loader(controlID) {
if (controlID == "ckBLBusinessUnits")
{
if (($('#ckBLBusinessUnits :checkbox:checked').length) >= 5)
{
alert("Maximum 5 BUs can be selected.");
modal = document.getElementById('loadingImage');
modal.style.display = "block";
}
}
if (controlID == "selectSegment") {
modal = document.getElementById('loadingImage');
modal.style.display = "block";
}
}
Now the issue here is, if i click little outside the checkboxes then JS method is triggered which means the loading image will be shown. At the same point there is no postback happening hence the image cannot be hidden(in C# selectSegment_SelectedIndexChanged
).
How can I handle the click outside the checkboxes?
Rendered HTML
<table id="ckBLBusinessUnits" onclick="loader(this.id);">
<tbody><tr>
<td><input id="ckBLBusinessUnits_0" type="checkbox" name="ckBLBusinessUnits$0" checked="checked" onclick="javascript:setTimeout('__doPostBack(\'ckBLBusinessUnits$0\',\'\')', 0)" value="BU 1"><label for="ckBLBusinessUnits_0">BU 1</label></td>
</tr><tr>
<td><input id="ckBLBusinessUnits_1" type="checkbox" name="ckBLBusinessUnits$1" onclick="javascript:setTimeout('__doPostBack(\'ckBLBusinessUnits$1\',\'\')', 0)" value="BU 2"><label for="ckBLBusinessUnits_1">BU 2</label></td>
</tr><tr>
<td><input id="ckBLBusinessUnits_2" type="checkbox" name="ckBLBusinessUnits$2" onclick="javascript:setTimeout('__doPostBack(\'ckBLBusinessUnits$2\',\'\')', 0)" value="BU 3"><label for="ckBLBusinessUnits_2">BU 3</label></td>
</tr><tr>
<td><input id="ckBLBusinessUnits_3" type="checkbox" name="ckBLBusinessUnits$3" onclick="javascript:setTimeout('__doPostBack(\'ckBLBusinessUnits$3\',\'\')', 0)" value="BU 4"><label for="ckBLBusinessUnits_3">BU 4</label></td>
</tr>
</tbody></table>