CreateUserWizard Validation?

Topics: General Help
Nov 19, 2008 at 2:46 AM

Hi I am trying to put the AIP control in my CreateUserWizardStep ContentTemplate so it's all on the one page. The control works and show the AIP image, filter and text however clicking on the create user button fails to fire an validation for the AIP control. I have tried adding a validationgroup and can not get it to work. Can anyone please help?




<%

@ Page Language="VB" AutoEventWireup="false" CodeFile="Rego.aspx.vb" Inherits="Rego" %>

 

<%

@ Register Assembly="DaveSexton.AutoInputProtection" Namespace="DaveSexton.Web.Controls"

 

 

TagPrefix="dsweb" %>

 

<!

 

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<

 

html xmlns="http://www.w3.org/1999/xhtml">

 

<

 

head runat="server">

 

 

<title>Untitled Page</title>

 

</

 

head>

 

<

 

body>

 

 

<form id="form1" runat="server">

 

 

<div>

 

 

<asp:CreateUserWizard ID="CreateUserWizard1" runat="server">

 

 

<WizardSteps>

 

 

<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">

 

 

<ContentTemplate>

 

 

<table border="0">

 

 

<tr>

 

 

<td align="center" colspan="2">

 

Sign Up for Your New Account

</td>

 

 

</tr>

 

 

<tr>

 

 

<td align="right">

 

 

<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User

 

Name:

</asp:Label>

 

 

</td>

 

 

<td>

 

 

<asp:TextBox ID="UserName" runat="server"></asp:TextBox>

 

 

<asp:RequiredFieldValidator ID="UserNameRequired" runat="server"

 

 

ControlToValidate="UserName" ErrorMessage="User Name is required."

 

 

ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

 

 

</td>

 

 

</tr>

 

 

<tr>

 

 

<td align="right">

 

 

<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>

 

 

</td>

 

 

<td>

 

 

<asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>

 

 

<asp:RequiredFieldValidator ID="PasswordRequired" runat="server"

 

 

ControlToValidate="Password" ErrorMessage="Password is required."

 

 

ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

 

 

</td>

 

 

</tr>

 

 

<tr>

 

 

<td align="right">

 

 

<asp:Label ID="ConfirmPasswordLabel" runat="server"

 

 

AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label>

 

 

</td>

 

 

<td>

 

 

<asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password"></asp:TextBox>

 

 

<asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server"

 

 

ControlToValidate="ConfirmPassword"

 

 

ErrorMessage="Confirm Password is required."

 

 

ToolTip="Confirm Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

 

 

</td>

 

 

</tr>

 

 

<tr>

 

 

<td align="right">

 

 

<asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label>

 

 

</td>

 

 

<td>

 

 

<asp:TextBox ID="Email" runat="server"></asp:TextBox>

 

 

<asp:RequiredFieldValidator ID="EmailRequired" runat="server"

 

 

ControlToValidate="Email" ErrorMessage="E-mail is required."

 

 

ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

 

 

</td>

 

 

</tr>

 

 

<tr>

 

 

<td align="right">

 

 

<asp:Label ID="QuestionLabel" runat="server" AssociatedControlID="Question">Security

 

Question:

</asp:Label>

 

 

</td>

 

 

<td>

 

 

<asp:TextBox ID="Question" runat="server"></asp:TextBox>

 

 

<asp:RequiredFieldValidator ID="QuestionRequired" runat="server"

 

 

ControlToValidate="Question" ErrorMessage="Security question is required."

 

 

ToolTip="Security question is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

 

 

</td>

 

 

</tr>

 

 

<tr>

 

 

<td align="right">

 

 

<asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Security

 

Answer:

</asp:Label>

 

 

</td>

 

 

<td>

 

 

<asp:TextBox ID="Answer" runat="server"></asp:TextBox>

 

 

<asp:RequiredFieldValidator ID="AnswerRequired" runat="server"

 

 

ControlToValidate="Answer" ErrorMessage="Security answer is required."

 

 

ToolTip="Security answer is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

 

 

</td>

 

 

</tr>

 

 

<tr>

 

 

<td align="right">

 

 

<asp:Label ID="LabelAIP" runat="server" AssociatedControlID="AutoInputProtectionControl1">Validate:</asp:Label>

 

 

</td>

 

 

<td>

 

 

<dsweb:AutoInputProtectionControl ID="AutoInputProtectionControl1" runat="server">

 

 

</dsweb:AutoInputProtectionControl>

 

 

</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="CreateUserWizard1"></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 ID="CompleteWizardStep1" runat="server">

 

 

</asp:CompleteWizardStep>

 

 

</WizardSteps>

 

 

</asp:CreateUserWizard>

 

 

</div>

 

 

</form>

 

</

 

body>

 

</

 

html>

 

Coordinator
Nov 19, 2008 at 6:46 AM
Hi,

In testing your example I found that adding the same ValidationGroup as the other controls on your page works for me: 

    <dsweb:AutoInputProtectionControl ID="AutoInputProtectionControl1" runat="server" ValidationGroup="CreateUserWizard1">
    </dsweb:AutoInputProtectionControl>

Now when I click the Create User button the form will not be submitted and I get a red asterisk next to the AIP text box until I enter a value.  And it will only continue to the next step of the wizard if the value that I enter is valid.

Are you sure that you tried ValidationGroup="CreateUserWizard1"?

- Dave
Nov 19, 2008 at 8:31 AM
Edited Nov 19, 2008 at 8:50 AM
Sorry my mistake, it does work like that. I was entering the wrong data for the AIP control and expecting an error message to be displayed in the validationsummary.

If i add the following code, when incorrect data is entered I do not get any error message, however this works outside of a createuserwizard.  

 

<

 

asp:ValidationSummary ID="ValidationSummary1" runat="server"

 

 

ValidationGroup="CreateUserWizard1" />

 


Thanks for the speedy reply, great control BTW.
Nov 19, 2008 at 8:57 AM
Okay I think I have narrowed it down. If I add a validationgroup on the normal page with a validationsummary it doesn't work either but will work without a validationgroup. Im going to have to try and debug the control, but I only have visual studio express :(
Coordinator
Nov 19, 2008 at 7:43 PM
Edited Nov 19, 2008 at 7:44 PM
Hi,

Thanks for the update.

There is this related problem, although I don't think it's causing your particular issue.

I tried explicitly assigning a value to the RequiredErrorMessage and InvalidErrorMessage properties but the text still didn't appear in the CreateUserWizard control's validation summary.  When I look at the raw HTML that is produced by your page the validators within the AIP control appear to be initialized in the exact same way as the validators outside of the control, so I'm not sure what the problem could be.

You should be able to use VC# Express to debug the code, although I'm going to look into it myself when I get some time (hopefully later tonight).  I'll get back to you when I find a solution.

- Dave
Nov 20, 2008 at 1:37 AM
Hi Dave,

No that related problem doesnt sound like the cause. I tried to debug the code but I couldnt work out how the code passes the errormessage to the validationsummary. Does this happen just by producing an errormessage?

As a further example you can see that this works

 

<dsweb:AutoInputProtectionControl ID="AutoInputProtectionControl1" runat="server">

 

 

</dsweb:AutoInputProtectionControl>

 

 

<asp:Button ID="Button1" runat="server" Text="Button" />

 

 

<asp:ValidationSummary ID="ValidationSummary1" runat="server" />


And this doesnt


 

 

<dsweb:AutoInputProtectionControl ID="AutoInputProtectionControl1" runat="server" ValidationGroup="aip">

 

 

 

 

 

</dsweb:AutoInputProtectionControl>

 

 

 

 

 

<asp:Button ID="Button1" runat="server" Text="Button" />

 

 

 

 

 

<asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="aip" />


But if you give the button a validationgroup too it does


 

 

<dsweb:AutoInputProtectionControl ID="AutoInputProtectionControl1" runat="server" ValidationGroup="aip">

 

 

 

 

 

</dsweb:AutoInputProtectionControl>

 

 

 

 

 

<asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="aip" />

 

 

 

 

 

<asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="aip" />

 

Nov 20, 2008 at 1:56 AM
I can get 
  • User validation is required

    to show for createuserwizard by clicking an empty AIP control with validationgroup set for AIP control and validationsummary.

    Maybe the problem is in protected override void CreateChildControls() in AutoInputProtectionControl.cs

    where the required.errormessage does not set a validationgroup????

  • Coordinator
    Nov 20, 2008 at 6:10 AM
    Hi, 

    Sorry but I had misunderstood your last issue.  Based on your examples it seems that you have been observing the correct behavior.

    > As a further example you can see that this works [snip]

    Yes, because all controls are participating in the default validation group since ValidationGroup is not assigned for any of them.

    > And this doesnt [snip]

    Yes, because the AIP control and the ValidationSummary control are participating in ValidationGroup="aip" while the button is still participating in the default validation group only.

    > But if you give the button a validationgroup too it does [snip]

    Yes, because all controls are now participating in the same validation group again (although this time it's the aip group, not the default group).

    If you assign controls to a ValidationGroup you must assign the button to the same ValidationGroup in order to trigger validation when it's clicked.

    Try replacing the AIP control in your examples with a regular TextBox and RequiredFieldValidator instead.  You should see the same exact behavior.

    - Dave
    Nov 20, 2008 at 6:41 AM
    Thats okay I understand that now. However for the createuserwizard with adding the validationgroup it still will only show the errormessage in the validationsummary for an empty AIP textbox and not if an incorrect entry is made?
    Nov 23, 2008 at 3:26 AM
    Hi Dave, you didn't answer my question. 

    Maybe the problem is in protected override void CreateChildControls() in AutoInputProtectionControl.cs where the required.errormessage does not set a validationgroup????

    As you can see from the code below, clicking create user without entering any text in the AIP produces the correct errormessage in the validationsummary however entering the incorrect text validation in the AIP control does not produce any errormessages in the validationsummary. Please help.

    <%

    @ Page Language="VB" AutoEventWireup="false" CodeFile="Rego.aspx.vb" Inherits="Rego" %>

     

    <%

    @ Register Assembly="DaveSexton.AutoInputProtection" Namespace="DaveSexton.Web.Controls"

     

     

    TagPrefix="dsweb" %>

     

    <!

     

    DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

     

    <

     

    html xmlns="http://www.w3.org/1999/xhtml">

     

    <

     

    head runat="server">

     

     

    <title>Untitled Page</title>

     

    </

     

    head>

     

    <

     

    body>

     

     

    <form id="form1" runat="server">

     

     

    <div>

     

     

    <asp:CreateUserWizard ID="CreateUserWizard1" runat="server">

     

     

    <WizardSteps>

     

     

    <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">

     

     

    <ContentTemplate>

     

     

    <table border="0">

     

     

    <tr>

     

     

    <td align="center" colspan="2">

     

    Sign Up for Your New Account

    </td>

     

     

    </tr>

     

     

    <tr>

     

     

    <td align="right">

     

     

    <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User

     

    Name:

    </asp:Label>

     

     

    </td>

     

     

    <td>

     

     

    <asp:TextBox ID="UserName" runat="server"></asp:TextBox>

     

     

    <asp:RequiredFieldValidator ID="UserNameRequired" runat="server"

     

     

    ControlToValidate="UserName" ErrorMessage="User Name is required."

     

     

    ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

     

     

    </td>

     

     

    </tr>

     

     

    <tr>

     

     

    <td align="right">

     

     

    <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>

     

     

    </td>

     

     

    <td>

     

     

    <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>

     

     

    <asp:RequiredFieldValidator ID="PasswordRequired" runat="server"

     

     

    ControlToValidate="Password" ErrorMessage="Password is required."

     

     

    ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

     

     

    </td>

     

     

    </tr>

     

     

    <tr>

     

     

    <td align="right">

     

     

    <asp:Label ID="ConfirmPasswordLabel" runat="server"

     

     

    AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label>

     

     

    </td>

     

     

    <td>

     

     

    <asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password"></asp:TextBox>

     

     

    <asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server"

     

     

    ControlToValidate="ConfirmPassword"

     

     

    ErrorMessage="Confirm Password is required."

     

     

    ToolTip="Confirm Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

     

     

    </td>

     

     

    </tr>

     

     

    <tr>

     

     

    <td align="right">

     

     

    <asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label>

     

     

    </td>

     

     

    <td>

     

     

    <asp:TextBox ID="Email" runat="server"></asp:TextBox>

     

     

    <asp:RequiredFieldValidator ID="EmailRequired" runat="server"

     

     

    ControlToValidate="Email" ErrorMessage="E-mail is required."

     

     

    ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

     

     

    </td>

     

     

    </tr>

     

     

    <tr>

     

     

    <td align="right">

     

     

    <asp:Label ID="QuestionLabel" runat="server" AssociatedControlID="Question">Security

     

    Question:

    </asp:Label>

     

     

    </td>

     

     

    <td>

     

     

    <asp:TextBox ID="Question" runat="server"></asp:TextBox>

     

     

    <asp:RequiredFieldValidator ID="QuestionRequired" runat="server"

     

     

    ControlToValidate="Question" ErrorMessage="Security question is required."

     

     

    ToolTip="Security question is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

     

     

    </td>

     

     

    </tr>

     

     

    <tr>

     

     

    <td align="right">

     

     

    <asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Security

     

    Answer:

    </asp:Label>

     

     

    </td>

     

     

    <td>

     

     

    <asp:TextBox ID="Answer" runat="server"></asp:TextBox>

     

     

    <asp:RequiredFieldValidator ID="AnswerRequired" runat="server"

     

     

    ControlToValidate="Answer" ErrorMessage="Security answer is required."

     

     

    ToolTip="Security answer is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

     

     

    </td>

     

     

    </tr>

     

     

    <tr>

     

     

    <td align="right">

     

     

    <asp:Label ID="LabelAIP" runat="server" AssociatedControlID="AutoInputProtectionControl1">Validate:</asp:Label>

     

     

    </td>

     

     

    <td>

     

     

    <dsweb:AutoInputProtectionControl ID="AutoInputProtectionControl1"

     

     

    runat="server" ValidationGroup="CreateUserWizard1">

     

     

    </dsweb:AutoInputProtectionControl>

     

     

    </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="CreateUserWizard1"></asp:CompareValidator>

     

     

    </td>

     

     

    </tr>

     

     

    <tr>

     

     

    <td align="center" colspan="2" style="color:Red;">

     

     

    <asp:ValidationSummary ID="ValidationSummary1" runat="server"

     

     

    ValidationGroup="CreateUserWizard1" />

     

     

    <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>

     

     

    </td>

     

     

    </tr>

     

     

    </table>

     

     

    </ContentTemplate>

     

     

    </asp:CreateUserWizardStep>

     

     

    <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">

     

     

    </asp:CompleteWizardStep>

     

     

    </WizardSteps>

     

     

    </asp:CreateUserWizard>

     

     

    </div>

     

     

    </form>

     

    </

     

    body>

     

    </

     

    html>

     

    Coordinator
    Nov 23, 2008 at 4:39 AM
    Hi,

    I can't reproduce the problem with your HTML.  When I click the Create User button after entering an invalid response into the AIP text box, the page posts back and I see, "The value you have entered does not match the image." in the validation summary, as expected.

    > Maybe the problem is in protected override void CreateChildControls() in AutoInputProtectionControl.cs where the required.errormessage does not set a validationgroup?

    No, there doesn't seem to be any problem with that code.  The ValidationGroup property is set on the required variable after it is cast to BaseValidator.  You can verify whether it's being assigned by examing the HTML of your page within the browser - near the bottom there will be a script block that assigns the validationgroup property of each of the AIP validator controls.

    I'd appreciate it if you could try to reproduce the problem in a simpler scenario.  Here's some HTML that's also templated and works fine for me.  Try adding some of your code-behind and your other controls one at a time until you can reproduce the problem.

    <asp:CreateUserWizard ID="CreateUserWizard1" runat="server" RequireEmail="false">

      <WizardSteps>

        <asp:CreateUserWizardStep runat="server">

          <ContentTemplate>

            <div><asp:TextBox runat="server" ID="UserName" ValidationGroup="CreateUserWizard1" /></div>

            <div><asp:TextBox runat="server" ID="Password" ValidationGroup="CreateUserWizard1" /></div>

            <div><asp:TextBox runat="server" ID="Question" ValidationGroup="CreateUserWizard1" /></div>

            <div><asp:TextBox runat="server" ID="Answer" ValidationGroup="CreateUserWizard1" /></div>

            <div>

              <dsweb:AutoInputProtectionControl runat="server" ID="aip" ValidationGroup="CreateUserWizard1">

              </dsweb:AutoInputProtectionControl>

            </div>

            <div>

              <asp:ValidationSummary runat="server" ValidationGroup="CreateUserWizard1" />

            </div>

          </ContentTemplate>

        </asp:CreateUserWizardStep>

        <asp:CompleteWizardStep runat="server" />

      </WizardSteps>

    </asp:CreateUserWizard>

    <!--EndFragment-->
    - Dave
    Nov 23, 2008 at 4:56 AM
    Thanks Dave that works.

    I think it comes down to crappy testing on my part. I was not entering any info in any of the other fields (ie username etc) and just entering the wrong data in the AIP control. This doesn't allow the AIP to validate as the other validation controls for username password are kicking first somehow. This is not a problem and I will be happy to implement this control instead of the one I have been using.

    Thanks again for all your help and it truly is the best open source captcha I have seen for asp.net.