A Better ASP.Net Member/Role Management Page Pt. 8
Prologue
It’s been over a year since I finished this series of posts, and I really thought I was done. I found however (now that I’m using it in production at work) that there is a slight oversight I plan on correcting in this post. This will be a “short, sweet and to the point” posting.
If you aren’t familiar with this series here’s the rundown. If you want to follow along with the other posts, you can create the management page yourself by reviewing all the posts for part 1, part 2, part 3, part 4, part 5, part 6 and part 7.
Problem
I found when using the management control, that when I created a user and there was an error creating the user account (such as a password that was too short), that the error wasn’t being presented to the administrator. The dialog just disappeared, no feedback (positive or negative) was given and the account wasn’t created.
Solution
Actually, the fix for this situation isn’t all that difficult. Since we’re utilizing the CreateUserWizard control, it has built in validation. This validation should be taking care of giving feedback to the administrator, HOWEVER, since we’re showing the CreateUserWizard in a ModalPopUp, we need to do a little extra work so that the administrator can see the actual message in the validation.
First, let’s start by adding another case to our SetUI subroutine. We want to add a CreateUserError entry to our SetUIModes Enum (just add CreateUserError as an item) and then we’ll add a case to our SetUI subroutine’s case statement. Add the following code to your SetUI Select Case statement:
Case SetUIModes.CreateUserError
mpeCreateUser.Show()
We’ll Call our SetUI subroutine and have it call this when we run into an error. This just pops up our mpeCreateUser popup. This is where we just were when we attempted to create the user. The CreateUserWizard control should be displaying our validation errors when it pops back up.
Next, we need to figure out when there has been an error in the CreateUserWizard control. We do this by adding code to the CreateUserWizard’s CreateUserError event handler. In this event handler, we want to call our SetUI code. Add the following to your cuwAddUser_CreateUserError event handler:
SetUI(SetUIModes.CreateUserError)
That’s it. All there is too it. The benefit of utilizing the CreateUserWizard’s internal validation, is we get the specific error messages that the CreateUserWizard returns AND they will be specific to how the membership provider is configured (i.e. specific to the password requirements, for example).
Epilogue
We have a saying here in the I.T. department at work, we like easy fixes (you know the errors we get because people are just clicking the wrong thing, for example). This falls into that category, an easy quick fix, relatively painless but necessary.