Last post Jan 13, 2009 12:36 PM by IMBack
Jun 19, 2006 07:33 AM|tlang|LINK
Has anyone successfully added a custom validation server control to a templated step
in the CreateUserWizard control? Is there something special you have to do to get it to
recognize the validation event?
What I did: 1) dragged a createuserwizard control onto the design surface
2) configured control for templates
3) dragged a custom validator control into the first step
4) double clicked the control, added some code in the validator event handler
5) ran the code in debug mode, breakpoint in event handler never gets hit.
Jun 20, 2006 03:50 AM|zhuhua1006|LINK
Jun 20, 2006 07:51 AM|mrd961981|LINK
Nohting Special, Just add the code like this :
System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
If (Your own Condition )
Jun 20, 2006 02:03 PM|PLBlum|LINK
The buttons of the CreateUserWizard are assigned a validation group name that is identical to the control's ID property. So assign that same value to the ValidationGroup property on your validators.
CustomValidator1.ValidationGroup = CreateUserWizard1.ID
Jun 22, 2006 01:47 PM|tlang|LINK
Thanks PLBLum! That was it! I needed to add it to the validation group. Without adding it to the validation group, the server event never fired.
Thanks to everyone who posted a response.
Jan 08, 2009 02:52 PM|IMBack|LINK
Hi I am trying to accomplish samething, I inluded a checkbox in CUW which is inside a LoginView control
<asp:CheckBox ID="cbid" runat="server"/>
<asp:CustomValidator ID="valCheckCheckBox" runat="server" ErrorMessage="Your
checkbox must be checked" ControlToValidate="cbid"
protected void CHECKBOX(object source, ServerValidateEventArgs args)
(Also included a breakpoint)
When the user clicks CreateUser button. this above function doesn't get executed. Later I will check if the checkbox was checked or not before creating a user.
Please let me know what am I missing?
Jan 10, 2009 01:24 PM|PLBlum|LINK
Here are the potential sources of problems.
1. The CustomValidator.ControlToValidate does not support the checkbox. Remove that property setting. Inside the CHECKBOX function, you will directly refer to cbid.Checked.
2. As a rule, a validator's evaluation method is not invoked if the ValidationGroup property does not match that of the button that fires validation. I see you are using ValidationGroup and it matches the default name of the CreateUser wizard. Double-check
the name. If you have setup buttons in a template, make sure they use the same ValidationGroup.
Jan 10, 2009 07:17 PM|IMBack|LINK
I removed ControlToValidate property and it worked.
I noticed that when I click create user button.
ie. if username or any other field was not entered or entered incorrectly, a * (star) is shown except for checkbox.
But if everything is entered correctly except for checkbox then the * (star) is displayed beside the checkbox.
I think the checkbox validation gets executed last or after everything else validates.
Is there away to show * (star) beside the checkbox as well when other fields validation fails.
Jan 11, 2009 09:11 AM|PLBlum|LINK
It all comes down to HTML. The * is really just "<span id="validatorid">*</span>". Its positioned after "<input type='checkbox'>" and contained in something else. In this case, your web form has enough space for it when you click submit because of the HTML
formatting at that time.
You will need to look at the container to that HTML and be sure it gives you plenty of space. A common HTML tag that causes problems is "<p>". If used, switch to <div>.
Jan 11, 2009 03:48 PM|IMBack|LINK
Jan 11, 2009 05:50 PM|yasserzaid|LINK
try this example
1. Drag and drop the CreateUserWizard Control to your Design mode.
2. Click on the arrow on the top right corner and pick 'Customize Create User Step'
3. Add a row and drag and drop a checkbox to the newly added row.
4. Go back to the Source mode and replace the visual-studio-generated checkbox code with this one. You can change the naming if you want.I keep it because i want it to be the same as the reference i got it from.
<asp:CheckBox ID="AcceptTermsCheckBox" runat="server" Text="Accept Terms" ValidationGroup="CreateUserWizard1" />
<asp:CustomValidator ID="ValTerms" ClientValidationFunction="AcceptTermsCheckBoxValidation" runat="server"
function AcceptTermsCheckBoxValidation(oSrouce, args)
var myCheckBox = document.getElementById('<%= (CreateUserWizard1.WizardSteps.Controls.FindControl("AcceptTermsCheckBox") as CheckBox).ClientID %>');
args.IsValid = false;
args.IsValid = true;
or in VB
function AcceptTermsCheckBoxValidation(source, args)
var vCheckBox = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("AcceptTermsCheckBox"), CheckBox).ClientID %>');
args.IsValid = false;
args.IsValid = true;
Don't forget to mark my as answer if it helps you
Jan 12, 2009 07:53 PM|PLBlum|LINK
The above post is a perfect answer. (Please mark it so).
Looking at the basic problem, you have setup client-side validation on all but the one case. Client-side validation occurs before the page is submitted. server side occurs after. In order to solve this problem in general, you have these options:
1. Adding client-side code to your customvalidator, as shown above.
2. Eliminating client-side validation, so it all happens consistently on the server side
3. Use an AJAX UpdatePanel combined with option #2 to give some effect of client-side validation (although it really doesn't happen on the client side)
FWIW: My commercial replacement to the ASP.NET validators,
Peter's Professional Validation, includes a checkbox validator (which I call CheckStateValidator as it handles radiobuttons too) that works on both client and server side. Its one of 20+ validators I've created.
Jan 12, 2009 10:04 PM|IMBack|LINK
Thanks Yasser for the example. Thanks Peter for your help. I wanted to mark couple of posts as "Answered" but couldn't because I am not the creator of the post. Unless there is a way to mark it please let me know so
I could mark it as answered. Thank you
Jan 13, 2009 12:17 AM|IMBack|LINK
Peter, Wanted to know your openion, what would you recommend "client-side validation" or "server side validation" in this case or in general? what would be better in performance? Thank you again.
Jan 13, 2009 12:12 PM|PLBlum|LINK
I recommend both, but consider Server side required. The idea is this:
1. Client-side provides a very interactive user interface, where an edit is immediately followed with a validation error response. It also reduces postbacks.
ASP.NET validation is designed with both of these in mind, and its very easy to use. Drop the necessary controls. On the server side, test Page.IsValid is true before saving the data in a Click method, or if using a different postback event handler, first
call Page.Validate() followed by the test for Page.IsValid.
I strongly recommend you look at my article,
http://aspalliance.com/699. You may also appreciate my tutorial for the deeper aspects of validation at
Jan 13, 2009 12:36 PM|IMBack|LINK
Thanks Peter for all your help.[Yes]