vendredi 10 mai 2019

ASP.NET checkbox won't postback when onclick is defined

I intend to answer my own question here - I think this could be difficult to fathom. I have two checkboxes, the second of which has a postback, which should only fire if the first one is checked. Here's what I wrote

    <asp:CheckBox ID="chkTC" runat="server" Text="I have read and accept the Terms & Conditions" /><br />
    <asp:CheckBox ID="chkRegister" runat="server" AutoPostBack="true" onclick =" var bOK = document.getElementById('chkTC').checked; if (!bOK) { alert('You must agree to the Terms and Conditions'); } return bOK; " />

The onclick code is a copy the code I use if I want to determine if a button should postback.

However, there was no postback from the second checkbox, even if the first was ticked.




Aucun commentaire:

Enregistrer un commentaire