Unlike a button, a check box does not have an OnClientClick event.
However, you can still use the OnClick event.
If you want your code to execute like a button click, you need to set AutoPostback = true.
One way to achieve this is by using the following code:
<asp:CheckBox ID="CheckBox1" runat="server"
OnClick="if (!confirm('really do this')) {return false;}"
AutoPostBack="True"/>
It's important to either let the JavaScript code continue or exit from it using return false. Otherwise, the post back will always occur. The rendered output of the above code snippet will be something like:
<input id="CheckBox1" type="checkbox" name="CheckBox1"
checked="checked"
onclick="if (!confirm('really do this')) {return false;};
setTimeout('__doPostBack(\'CheckBox1\',\'\')', 0)">
With a check box, simply returning true or false in an OnClick event won't prevent the post back. You have to handle it differently compared to buttons where you can use return confirm('Please hit ok') to control the post back behavior.
A button's OnClientClick() return value determines if the post back will fire, but this doesn't apply to check boxes. However, by tricking the page processor with OnClick(), you can control whether or not the post back code executes based on confirmation.
In summary, a check box doesn't fully support OnClientClick like buttons do, but with the right JavaScript manipulation in the OnClick event, you can control the post back behavior effectively.