Hi Corobori,
Page.IsValid is calculated serverside and doesn't know that you switched the javascript validation off clientside.
Serverside you can check wheter Checkbox1 is checked to ignore validation i.e. add runat="server" to the checkbox.
HTML
UserName:
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="valName" ControlToValidate="txtName" runat="server"
ErrorMessage="*Required" ForeColor="Red" ValidationGroup="Group1" />
<br />
Enable Validation:
<input type="checkbox" id="CheckBox1" onclick="ToggleValidator(this);" checked="checked"
runat="server" />
<br />
<asp:Button ID="Button1" Text="Submit" runat="server" ValidationGroup="Group1" OnClick="Submit" />
<script type="text/javascript">
function ToggleValidator(chk) {
var valName = document.getElementById("<%=valName.ClientID%>");
ValidatorEnable(valName, chk.checked);
}
</script>
C#
protected void Submit(object sender, EventArgs e)
{
if (IsValid || !CheckBox1.Checked)
{
}
else
{
}
}
VB.Net
Protected Sub Submit(ByVal sender As Object, ByVal e As EventArgs)
If IsValid OrElse Not CheckBox1.Checked Then
Else
End If
End Sub