So I made a working bit of code (javascript) to validate a Terms Of Use checkbox.
When the checkbox and CustomValidator are inside The "CreateUserWizard" form It won't work.
Outside it, there's no problems. My code is:
<asp:CheckBox ID="AcceptTermsCheckBox" runat="server" Text=" I agree to the Detelli Property Network"
Font-Size="8" ForeColor="#133792" ValidationGroup="CreateUserWizardControl" /><br />
<asp:HyperLink runat="server" NavigateUrl="Terms.aspx"
ForeColor="#133792" Font-Underline="true" ID="Terms" Font-Size="8">terms of use.</asp:HyperLink><br />
<asp:CustomValidator ID="ValTermsCheckBox" ClientValidationFunction="AcceptTermsCheckBoxValidation"
runat="server" ErrorMessage="Please accept Terms and Conditions." ValidationGroup="CreateUserWizardControl" OnServerValidate="ValTermsCheckBox_ServerValidate">
</asp:CustomValidator>
And my javascript code, that I can only place outside the "CreateUserWizard" form, is:
<script language="javascript" type="text/javascript">
function AcceptTermsCheckBoxValidation(source, args)
{
args.IsValid = document.getElementById(
'<%= AcceptTermsCheckBox.ClientID %>').checked;
}
</script>
I've been trying to write some Visual Basic in the code behind that I can use,
but it's not working, no matter what I do it pulls up the error as though the checkbox is unchecked.
Protected Sub ValTermsCheckBox_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
Dim AcceptTermsCheckBox As CheckBox = CreateUserWizardStep1.Controls(0).FindControl("AcceptTermsCheckBox")
If AcceptTermsCheckBox.Checked = True Then
args.IsValid =
True
End If
End Sub
This is really leaving me stumped, any ideas would be greatly appreciated.
Thank you in advance
Be sure to visit
www.detelli.comAnd please remember to click ?Mark as Answer? on the post that helps you.
This can be beneficial to other community members reading the thread.