I am checking if any of the check boxes (which is one of the columns) are checked. If not then when user clicks the button it will get a alert message otherwise user get the Confirm message for Cancellation. But I am getting error:
BC30451: 'cbSOCan' is not declared. It may be inaccessible due to its protection level
Following are my codes:
.Aspx
<asp:TemplateField HeaderText="Cancel SO Line Item">
<asp:TemplateField HeaderText="Cancel SO Line Item">
<ItemTemplate>
<asp:checkbox ID="cbSOCan" runat="server" ViewStateMode="Enabled" EnableViewState="true" CausesValidation="False" EnableTheming="False"></asp:checkbox>
</ItemTemplate>
</asp:TemplateField>
</asp:TemplateField>
<asp:LinkButton CssClass="btn btn-primary" ID="btnCancelItem" runat="server" CausesValidation="False"
OnClientClick="return validate();"> Cancel Item</asp:LinkButton>
JS
<script>
var atLeast = 1
function validate() {
var result = confirm('Are you sure you want to Cancel selected SO line Items?');
var CHK = document.getElementById("<%=cbSOCan.ClientID%>");
var checkbox = CHK.getElementsByTagName("input");
var counter = 0;
for (var i = 0; i < checkbox.length; i++) {
if (checkbox[i].checked) {
counter++;
}
}
if (atLeast > counter) {
alert("Please select atleast " + atLeast + " item(s)");
return false;
}
return true;
}
</script>
Aucun commentaire:
Enregistrer un commentaire