Blogger :
Scott on Writing
All posts :
All posts by Scott on Writing
Category :
ASP.NET
Blogged date : 2008 Jul 24
The CreateUserWizard control introduced in ASP.NET 2.0 makes it easy to create a new user account on a website that uses the Membership framework. (See my Creating User Accounts tutorial for more information on using this control.) Out of the box, the CreateUserWizard control offers a fully functional interface for creating new user accounts. You don't have to write a lick of code or declarative markup. Instead, just set a few properties and you're off and running.
Teach Yourself ASP.NET 3.5 in 24 Hours reader Jason L. e-mailed me recently with an interesting observation about the behavior of the CreateUserWizard's validation functionality. The CreateUserWizard control's default user interface includes validation controls for the various input fields. For example, there are RequiredFieldValidator controls to ensure that the visitor enters values for the username, password, e-mail, and so on. The ErrorMessage property values of these validation controls can be customized via the CreateUserWizard control's properties, such as UserNameRequiredErrorMessage and EmailRequiredErrorMessage.
Regardless of the values you use for the ErrorMessage properties, the RequiredFieldValidator controls have their Text properties values all set to the same thing, an asterisk (*). When a validation control is both its Text and ErrorMessage properties assigned, the value of the Text property is displayed in the location of the validation control in the event of invalid data; the value of the ErrorMessage property is displayed in a ValidationSummary control (if one exists on the page).
For whatever reason, the default CreateUserWizard control user interface does not include a ValidationSummary control. Consequently, the values specified in the UserNameRequiredErrorMessage and EmailRequiredErrorMessage properties (among the other ErrorMessage-related properties) are never displayed. (Granted, these property values are assigned to the tool tip of the validation controls, meaning that a user can hover her mouse over the asterisk and see a more detailed ErrorMessage description.) Interestingly, the CreateUserWizard's default interface does show a message if the password and confirmation password do not match. This behavior is due to the fact that the default interface includes a CompareValidator control that does not have its Text property set. Rather, only its ErrorMessage property is assigned (and this can be customized via the CreateUserWizard control's ConfirmPasswordCompareErrorMessage property).
So how do you get the ErrorMessage properties for the RequiredFieldValidator controls to display when using the default interface? One way is to add your own ValidationSummary control to the page. If you do this piece sure to set a ValidationSummary control's ValidationGroup property to the ID of the CreateUserWizard control. In other words, if the CreateUserWizard is named MyCreateUserWizard then set the ValidationSummary control's ValidationGroup property to "MyCreateUserWizard". However, if the user enters a password that does not match with the confirm password the corresponding error message will be displayed twice: once by the CompareValidator and again in the ValidationSummary control.
The only sure fire way to get the validation messages to display as expected is to customize the user interface created by the CreateUserWizard. The good news is that it is very easy to convert the CreateUserWizard into a template, at which point you have virtually unlimited customization capabilities regarding the validation logic and display. For more information on customizing the CreateUserWizard control's user interface, check out Customizing the CreateUserWizard Control and Storing Additional User Information.