Search code examples
asp.netc#-4.0checkboxservercontrols

ASP.NET C# Checkbox Realtime Validation


Trying to get two checkbox controls to work with each other. Pseudo-code example:

If Checkbox 1 is checked, 
Look at checkbox 2 and make sure it is not checked.
If checkbox 2 is checked, then uncheck Checkbox 2.

and Vice Versa.

I kind of have it, but it wont update until I press a submit button. Is there a way to run the pseudo-code without pressing submit first? I tried using:

<asp:CheckBox ID="World1" runat="server" OnCheckedChanged="World1Changed" />

but in the codebehind file it still won't update without pressing submit.


Solution

  • Just add AutoPostBack="true" to your checkbox.