Reputation: 195
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" />
Upvotes: 1
Views: 5927
Reputation: 5977
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...
Upvotes: 0
Reputation: 11721
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
Upvotes: 4