How to fire validation in CreateUserWizard next button?

W

winnie_us99

Hi All,

I am trying to do validation on my text field before going to the
next page to create a user. It doesn't look like the next button will
fire any validation. Am I missing something? Can anyone please help me
with this?

I am attaching my code piece. Thank you in advance for your help.

Wing

------ My Code Piece ------

<asp:CreateUserWizard ID="cuwCreateUser" runat="server"
OnCreatedUser="cuwCreateUser_CreatedUser" Width="90%"
OnNextButtonClick="cuwCreateUser_NextButtonClick">
<WizardSteps>
<asp:WizardStep runat="server" StepType="Start"
Title="Additional Information" ID="wsStep1">
<table border="0" style="font-size: 100%; width:
100%;">
<tr>
<td align="center" colspan="2">
<strong>Create New
User</strong></td>
</tr>
<tr>
<td style="text-align: right; width:
25%">First Name:</td>
<td align="left"><asp:TextBox
ID="txtFirstName" runat="server" Width="90%"></asp:TextBox>
<asp:RequiredFieldValidator
ID="FirstNameRequired" runat="server" ControlToValidate="txtFirstName"
ErrorMessage="First Name is
required." ToolTip="First Name is required."

ValidationGroup="cuwCreateUser">*</asp:RequiredFieldValidator></td>
</tr>
</table>
</asp:WizardStep>
<asp:CreateUserWizardStep runat="server" Title="Add
User">
<ContentTemplate>
<table border="0" style="font-size: 100%;
width: 100%">
<tr>
<td align="center" colspan="2">
<strong>Create New User (Con't)
</strong></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td style="text-align: right; width:
25%">
<asp:Label ID="UserNameLabel"
runat="server" AssociatedControlID="UserName">Login
Name:</asp:Label></td>
<td style="width: 283px; text-align:
left">
<asp:TextBox ID="UserName"
runat="server" Width="90%"></asp:TextBox>
<asp:RequiredFieldValidator
ID="UserNameRequired" runat="server" ControlToValidate="UserName"
ErrorMessage="User Name is
required." ToolTip="User Name is required."
ValidationGroup="cuwCreateUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="PasswordLabel"
runat="server"
AssociatedControlID="Password">Password:</asp:Label></td>
<td style="width: 283px; text-align:
left">
<asp:TextBox ID="Password"
runat="server" TextMode="Password" Width="90%"></asp:TextBox>
<asp:RequiredFieldValidator
ID="PasswordRequired" runat="server" ControlToValidate="Password"
ErrorMessage="Password is
required." ToolTip="Password is required."
ValidationGroup="cuwCreateUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label
ID="ConfirmPasswordLabel" runat="server"
AssociatedControlID="ConfirmPassword">Confirm
Password:</asp:Label></td>
<td style="width: 283px; text-align:
left">
<asp:TextBox ID="ConfirmPassword"
runat="server" TextMode="Password" Width="90%"></asp:TextBox>
<asp:RequiredFieldValidator
ID="ConfirmPasswordRequired" runat="server"
ControlToValidate="ConfirmPassword"
ErrorMessage="Confirm Password
is required." ToolTip="Confirm Password is required."

ValidationGroup="cuwCreateUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="EmailLabel"
runat="server" AssociatedControlID="Email">E-mail:</asp:Label></td>
<td style="width: 283px; text-align:
left">
<asp:TextBox ID="Email"
runat="server" Width="90%"></asp:TextBox>
<asp:RequiredFieldValidator
ID="EmailRequired" runat="server" ControlToValidate="Email"
ErrorMessage="E-mail is
required." ToolTip="E-mail is required."
ValidationGroup="cuwCreateUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="QuestionLabel"
runat="server" AssociatedControlID="Question">Security
Question:</asp:Label></td>
<td style="width: 283px; text-align:
left">
<asp:TextBox ID="Question"
runat="server" Width="90%"></asp:TextBox>
<asp:RequiredFieldValidator
ID="QuestionRequired" runat="server" ControlToValidate="Question"
ErrorMessage="Security question
is required." ToolTip="Security question is required."

ValidationGroup="cuwCreateUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="AnswerLabel"
runat="server" AssociatedControlID="Answer">Security
Answer:</asp:Label></td>
<td style="width: 283px; text-align:
left">
<asp:TextBox ID="Answer"
runat="server" Width="90%"></asp:TextBox>
<asp:RequiredFieldValidator
ID="AnswerRequired" runat="server" ControlToValidate="Answer"
ErrorMessage="Security answer
is required." ToolTip="Security answer is required."

ValidationGroup="cuwCreateUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:CompareValidator
ID="PasswordCompare" runat="server" ControlToCompare="Password"

ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The
Password and Confirmation Password must match."

ValidationGroup="cuwCreateUser"></asp:CompareValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2"
style="color: red">
<asp:Literal ID="ErrorMessage"
runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
</table>
</ContentTemplate>
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep runat="server">
<ContentTemplate>
<table border="0" style="font-size: 100%;
width: 410px">
<tr>
<td align="center" colspan="2">
<strong>
Complete</strong></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td>
New user has been successfully
created.</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="ContinueButton"
runat="server" CausesValidation="False" CommandName="Continue"
OnClick="ContinueButton_Click"
Text="Continue" ValidationGroup="cuwCreateUser" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
 
K

Ken Cox - Microsoft MVP

Hi Wing,

It seems to fire if you take out the ValidationGroup value, cuwCreateUser.

I wonder if this has something to do with it: "When you specify a value for
the ValidationGroup property, only the validation controls that are part of
the specified group are validated"

Ken

Microsoft MVP [ASP.NET]
 
W

Wing

Hi Ken,

Thanks, it works. Well, I have another question would like to ask.
I would like to do a database lookup to validate if the user entered an
existed First Name when the Next button being clicked. I found that
there is a OnNextButtonClick event and I have put code there for
validation. I have put a label for error message on the WizardStep page
to show error message when database validation failed. When I clicked
on the next button, the validation complete and the error message
becomes visible and the it moves on to the second page. How can I keep
the user in the first page with the error message?

Thanks,
Wing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top