I have an ASP.NET checkbox, and I want to run some javascript before it posts back.
Something like:
<asp:CheckBox ID="chkSelected" runat="server" AutoPostBack="True" OnCheckedChanged="chkSelected_CheckedChanged" />
but I want to run a JS confirm dialog when the user click it, and if they were UNCHECKING it, I’d like to ask them if they’re sure, and if so, postback and run my serverside code. If they say No, don’t postback at all.
Anyone know of an ‘easy’ way to do this?
You can add an
onclickhandler:(I believe this will work, but I didn’t try it)
You can also add an event in Javascript. (which is more likely to work)
Using jQuery: