2

I am using the built-in asp.net membership framework. I created a registration page and set up client-side validation with some custom validators, validating through jQuery AJAX to a web service and the client-side validation works ok. I have two issues:

  1. Even when the client-side validation fails, the continue button still works. How do I disable it?

  2. I don't want to count on client-side validation. How do I go about implementing server-side validation in the CreateUserWizard? Can you point me at some specific tutorial? I failed to find one.

Thank you!

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Elad Lachmi
  • 10,406
  • 13
  • 71
  • 133

2 Answers2

3

Use event CreatingUser.

Markup:

<asp:CreateUserWizard runat="server" CreatingUser="wizard_CreatingUser" />

Code:

protected void wizard_CreatingUser (object sender, LoginCancelEventArgs e)
{
    e.Cancel = ((CreateUserWizard)sender).UserName.Contains("!@#$%^&");
}
abatishchev
  • 98,240
  • 88
  • 296
  • 433
  • @abatishchev - That is more or less what I was looking for, but how do I invalidate the control so the right error message is displayed? – Elad Lachmi May 11 '11 at 16:25
  • @Elad: Than I recommend you to expand CreateUserWizard into table and use CustomValidator against one of text fields – abatishchev May 12 '11 at 07:24
  • @abatishchev - I already expanded it to a template and used a table. I'm just not sure how I go about the server-side validation. The client-side validation is already working. – Elad Lachmi May 12 '11 at 09:13
  • @Elad: Use [CustomValidator.ServerValidate](http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.servervalidate.aspx) event to perform other-validators-like but server-side validation – abatishchev May 12 '11 at 10:24
  • @abatishchev - So aside from implementing the validation in a seperate function for each validator control, I also need to revalidate the entire form in CreatingUser? – Elad Lachmi May 12 '11 at 11:21
  • @Elad: If server-side validation will be enough, I think you can skip CreatingUser. This event is for some global, not local specific (like input) validation, e.g. system consistence, etc – abatishchev May 12 '11 at 11:30
  • Thank you! I'll go with that. Once last thing. How do I stop the CreatingUser event from firing if the controls don't validate client / server side? – Elad Lachmi May 12 '11 at 13:05
  • @Elad: If I understood you correctly, CreateUserWizard will not create a user (and not fire the event) if any of validators on a page will fail. Did I? – abatishchev May 12 '11 at 13:25
  • @abatishchev - I have not put any server-side validation in yet, but for client-side validation it goes through (and fires the event) even if the client-side validation fails. – Elad Lachmi May 12 '11 at 13:41
  • @Elad: Very strange. Take a look [here](http://pastebin.com/wqxejhf0), that works in some my web app project. Client-side validation doesn't allow user to be created – abatishchev May 12 '11 at 13:59
  • @abatishchev - I just checked. I have a compare validator to check password and password confirmation and the user is created even if the passwords don't match. I'm guessing this has to do with the wizard needing only the password field "officialy" (Hope you understand what I'm trying to say :)) – Elad Lachmi May 12 '11 at 23:01
  • Ok. Got it going now. I just didn't have the submit button on the same ValidationGroup as the rest of the controls. Thank you! – Elad Lachmi May 12 '11 at 23:18
1

Please look on the following tutorials for full information about the CreateUserWizard: Customizing the CreateUserWizard Control.

Another helpful tutorial can be found here: Customizing ASP.NET's CreateUserWizard Control To Display a Fixed Set of Security Questions

Koby Mizrahy
  • 1,361
  • 2
  • 12
  • 23