Scott on Writing

Musings on technical writing...

The CreateUserWizard and Validation ErrorMessages

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.

posted on Thursday, July 24, 2008 10:41 AM

Feedback

# re: The CreateUserWizard and Validation ErrorMessages 7/25/2008 10:44 AM Bharath Reddy VasiReddy

Simple and nice stuff to read.
Thankyou.

# re: The CreateUserWizard and Validation ErrorMessages 7/25/2008 5:30 PM Andrei Rinea

I wish the whole Membership set of controls would be replaced with better ones.

Very often I need to have an authentication/authorization mechanism that doesn't need a username but an e-mail.

I need email verification and in case the user loses the password he/she should be able to recover it without knowing (a) username.

# Email Verification for New Accounts via ASP.NET's Membership Framework 7/25/2008 8:54 PM Scott on Writing

# re: The CreateUserWizard and Validation ErrorMessages 7/25/2008 9:00 PM Scott Mitchell

Andrei, check out this blog post... I wrote it as a follow-up to your comment here.
http://scottonwriting.net/sowblog/posts/13426.aspx

Thanks

# Email Verification for New Accounts via ASP.NET's Membership Framework 7/25/2008 9:12 PM BusinessRx Reading List

In my last blog entry, The CreateUserWizard and Validation ErrorMessages , reader Andrei Rinea commented:

# Email Verification for New Accounts via ASP.NET's Membership Framework 7/25/2008 9:27 PM Community Blogs

In my last blog entry, The CreateUserWizard and Validation ErrorMessages , reader Andrei Rinea commented

# Email Verification for New Accounts via ASP.NET's Membership Framework 7/25/2008 10:59 PM Readed By Wrocław NUG members

In my last blog entry, The CreateUserWizard and Validation ErrorMessages , reader Andrei Rinea commented

# Recent URLs tagged Validation - Urlrecorder 8/31/2008 10:16 PM Pingback/TrackBack

Recent URLs tagged Validation - Urlrecorder

Title:  
Name:  
Url:
Protected by Clearscreen.SharpHIPEnter the code you see:
Comments   

My Links

Ads Via DevMavens

Archives

Post Categories

 

I am a Microsoft MVP for ASP.NET.
I am an ASPInsider.
<July 2009>
SMTWTFS
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

Comment Stats

DayTotal% of Total
Sunday 2046.9%
Monday 42314.3%
Tuesday 50116.9%
Wednesday 54518.4%
Thursday 57219.3%
Friday 53618.1%
Saturday 1856.2%
Total 2966100.0%

Hour1Total% of Total
12:00 AM 752.5%
1:00 AM 802.7%
2:00 AM 672.3%
3:00 AM 812.7%
4:00 AM 642.2%
5:00 AM 1234.1%
6:00 AM 1153.9%
7:00 AM 1755.9%
8:00 AM 1876.3%
9:00 AM 1565.3%
10:00 AM 1866.3%
11:00 AM 1926.5%
12:00 PM 1996.7%
1:00 PM 1846.2%
2:00 PM 1675.6%
3:00 PM 1344.5%
4:00 PM 1153.9%
5:00 PM 1063.6%
6:00 PM 993.3%
7:00 PM 1063.6%
8:00 PM 903.0%
9:00 PM 842.8%
10:00 PM 893.0%
11:00 PM 923.1%
Total 2966100.0%

Comments by Blog Entry Date/Time

Day Entry MadeAvg.Total
Sunday 4.91157
Monday 4.92379
Tuesday 4.21471
Wednesday 7.42668
Thursday 6.53666
Friday 5.17450
Saturday 4.73175
Total 5.522966

Hour1 Entry MadeAvg.Total
12:00 AM 5.2937
1:00 AM 1.002
5:00 AM 0.000
7:00 AM 4.0048
8:00 AM 4.29133
9:00 AM 6.04290
10:00 AM 5.83274
11:00 AM 4.36192
12:00 PM 6.44348
1:00 PM 3.14132
2:00 PM 5.04227
3:00 PM 7.97303
4:00 PM 3.8199
5:00 PM 6.00168
6:00 PM 4.56114
7:00 PM 8.95188
8:00 PM 8.58163
9:00 PM 5.00115
10:00 PM 6.31101
11:00 PM 4.5732
Total 5.522966

Learn More About Comment Stats
1 - All times GMT -8...


Blog Stats

Favorite Web Sites

My Books

My MSDN Articles