1

how can i check / uncheck the following ASP checkbox with JQuery?

<asp:CheckBox ID="cbImg1" CssClass="cbImg1" Checked="true" Visible="false" ClientIDMode="Static" runat="server" Width="130px" ForeColor="#909090" Font-Size="12px" />
user281812
  • 195
  • 3
  • 14

2 Answers2

4

Your code :-

<asp:CheckBox ID="cbImg1" CssClass="cbImg1" Checked="true" Visible="false" ClientIDMode="Static" runat="server" Width="130px" ForeColor="#909090" Font-Size="12px" />

in jQuery you can try prop() :-

$("#cbImg1").prop('checked', true); //// To check
$("#cbImg1").prop('checked', false); //// To un check
Neel
  • 11,625
  • 3
  • 43
  • 61
  • i think the issue is that i have update button and after i press it the checkbox control gets the value Checked="true". is it true? if yes how can i avoid it? – user281812 Jul 22 '15 at 06:09
  • i dont think update button changes the state of checkbox unless there are some code done on that..your asp checkbox already having Checked="true" in ur question by the way! – Neel Jul 22 '15 at 06:14
  • do you require to make it visible ="false" ? i guess it is creating problem @user281812 – Neel Jul 22 '15 at 06:24
  • i changed it with no result – user281812 Jul 22 '15 at 06:27
  • check this http://stackoverflow.com/questions/1523606/asp-net-checkbox-value-at-postback-is-wrong @user281812 – Neel Jul 22 '15 at 06:28
  • sorry but i didnt understand the solution – user281812 Jul 22 '15 at 06:47
0

First change your

<asp:CheckBox ID="cbImg1" CssClass="cbImg1" Checked="true" Visible="false" ClientIDMode="Static" runat="server" Width="130px" ForeColor="#909090" Font-Size="12px" />

to

  <asp:CheckBox ID="cbImg1" CssClass="cbImg1" Checked="true" style="display:none" ClientIDMode="Static" runat="server" Width="130px" ForeColor="#909090" Font-Size="12px" />

remove Visible="false" and make it to display none.

Then let's say you have button, add the following script to it.

OnClientClick="buttonClick(); return false;

And add the javascript like...

   <script type="text/javascript">
                function buttonClick() {      

        $("#<%=cbImg1.ClientID %>").prop('checked', true);
        alert('Called');
       }


      </script>

See if the alert appears or not...

Jigar Pandya
  • 6,004
  • 2
  • 27
  • 45