I have now figured it out, and for anyone having the same concern, here's what I did.
In the end I did not use any code behind so ignore that. looking at the origianal code (javascript, checkbox, and custom validator) I discovered that the javascript could not find checkbox once it was imbeded into the "CreateUserWizard". So all I had to
do was give it a proper location.
<script type="text/javascript">
function AcceptTermsCheckBoxValidation(source, args)
I tried to put the Javascript codes in the .js file and included the .js file in the .aspx. I find that the object will be null (due to document.getElementById can not get the object). Any idea?
I had errors when I put it in a .js file, mainly because I'm using MasterPages, try just putting the code in your page outside of the CreateUserWizard section. If you're still having errors, post your code and errors.
Web:www.Detelli.com Please remember to mark the post as answer that solves your issue.
This will be greatly benificial for other users.
If youwant to debug in JavaScript it has a JavaScript cConsole. itwill tell you what the JavaScript Error is when you look at it. Also you can install the firebug extension to get even better control over the errors. [getFirebug.com]
darkknight18...
Contributor
2674 Points
1040 Posts
CreateUserWizard Check Box validation Problem
Apr 24, 2007 12:03 AM|LINK
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 SubThis is really leaving me stumped, any ideas would be greatly appreciated.
Thank you in advance
Please remember to mark the post as answer that solves your issue.
This will be greatly benificial for other users.
darkknight18...
Contributor
2674 Points
1040 Posts
Re: CreateUserWizard Check Box validation Problem
Apr 25, 2007 02:50 PM|LINK
I have now figured it out, and for anyone having the same concern, here's what I did.
In the end I did not use any code behind so ignore that. looking at the origianal code (javascript, checkbox, and custom validator) I discovered that the javascript could not find checkbox once it was imbeded into the "CreateUserWizard". So all I had to do was give it a proper location.
<script type="text/javascript">
function AcceptTermsCheckBoxValidation(source, args)
{
args.IsValid = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("AcceptTermsCheckBox"), CheckBox).ClientID %>')
if (!args.IsValid.checked)
{
ValTerms.Validate;
return false;
}
else {
return true;
}
}
</
script><
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="ValTerms" ClientValidationFunction="AcceptTermsCheckBoxValidation" runat="server" ErrorMessage="Please Accept Terms Of Use." ValidationGroup="CreateUserWizardControl"> </asp:CustomValidator>I haven't tested this on anything other than IE but I'm sure it's fine.
It took forever but it feels so good to beat that code.
Good Luck to all.
Please remember to mark the post as answer that solves your issue.
This will be greatly benificial for other users.
Goldfish
Member
18 Points
25 Posts
Re: CreateUserWizard Check Box validation Problem
May 17, 2007 09:39 PM|LINK
I tried to put the Javascript codes in the .js file and included the .js file in the .aspx. I find that the object will be null (due to document.getElementById can not get the object). Any idea?
Thanks.
darkknight18...
Contributor
2674 Points
1040 Posts
Re: CreateUserWizard Check Box validation Problem
May 19, 2007 01:44 AM|LINK
I had errors when I put it in a .js file, mainly because I'm using MasterPages, try just putting the code in your page outside of the CreateUserWizard section. If you're still having errors, post your code and errors.
Please remember to mark the post as answer that solves your issue.
This will be greatly benificial for other users.
Mattw67
Member
355 Points
491 Posts
Re: CreateUserWizard Check Box validation Problem
Jan 18, 2008 03:56 AM|LINK
Kool thanks!
This is exactly what i needed.
But it doesn't work with Firefox :-(
And i need it with Firefox.
Someone have an idea why it is not working with Firefox?
N.B. Dont works for me with IE 6 in a .js external file.
A1ien51
All-Star
29935 Points
5821 Posts
Re: CreateUserWizard Check Box validation Problem
Jan 18, 2008 05:04 PM|LINK
If youwant to debug in JavaScript it has a JavaScript cConsole. itwill tell you what the JavaScript Error is when you look at it. Also you can install the firebug extension to get even better control over the errors. [getFirebug.com]
Eric
A1ien51
All-Star
29935 Points
5821 Posts
Re: CreateUserWizard Check Box validation Problem
Jan 18, 2008 05:06 PM|LINK
What is ValTerms.Validate;
Does not look like valid JavaScript to me.
Eric
Mattw67
Member
355 Points
491 Posts
Re: CreateUserWizard Check Box validation Problem
Jan 18, 2008 05:17 PM|LINK
<asp:CustomValidator ID="ValTerms" ClientValidationFunction="AcceptTermsCheckBoxValidation"
runat="server" ErrorMessage="Please Accept Terms Of Use." ValidationGroup="CreateUserWizardControl">
</asp:CustomValidator>darkknight18...
Contributor
2674 Points
1040 Posts
Re: CreateUserWizard Check Box validation Problem
Jan 19, 2008 12:09 AM|LINK
Check it on my site on the register page in firefox.
I am still using the same code, and it works great.
www.detelli.com/register.aspx
Please remember to mark the post as answer that solves your issue.
This will be greatly benificial for other users.
Mattw67
Member
355 Points
491 Posts
Re: CreateUserWizard Check Box validation Problem
Jan 19, 2008 12:51 AM|LINK
Hummm, can you show me your actual code please...
Is your Terms of use checkbox still inside the CreateUserWizard and your submit button?
Thanks