Hi @Aypn CNN
- Get the ID of the asp.net control converted to HTML control
-
- Write js code for the Checkbox control (pay attention to the method of using client code)
<label for="chbox1">
<asp:CheckBox id="chbox1" runat="server" onclick="judge(this)" />
</label>
<label for="chbox2">
<asp:CheckBox id="chbox2" runat="server" />
</label>
3.Get the value of label and the number of checkboxes selected. Finally, add it up to make an if judgment.
<script type="text/javascript">
function judge(chbox1) {
var num = document.getElementById("GridView1_D1_0").innerText;
var checkboxnum = 0;
var maxnum = 6;
var checkcount = 0;
for (let i = 0; i < maxnum; i++)
{
if (document.getElementById("GridView2_chbox1_" + checkboxnum).checked == true) {
checkcount = checkcount + 1;
}
checkboxnum = checkboxnum + 1;
}
var result = parseInt(num) + parseInt(checkcount);
if (result != 4) {
alert(result);
alert("Error");
}
}
function judge(chbox2) {
var num = document.getElementById("GridView1_D2_0").innerText;
var checkboxnum = 0;
var maxnum = 6;
var checkcount = 0;
for (let i = 0; i < maxnum; i++) {
if (document.getElementById("GridView2_chbox2_" + checkboxnum).checked == true) {
checkcount = checkcount + 1;
}
checkboxnum = checkboxnum + 1;
}
var result = parseInt(num) + parseInt(checkcount);
if (result != 4) {
alert(result);
alert("Error");
}
}
Result:
Best Regards
Qi You
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.