The code below has always worked, but now somehow I can't submit the form anymore even though I provide both username and password. I get no errors in backend or the Chrome Developer Console. I tried enabling/disabling all validators and found that if I add Enabled="false" to validator UserNameRequired, the form does submit. But obviously I want to have this requiredfieldvalidator enabled.
Why is this happening?
You can also see it live here (fill in a random email address/password): http://www.zorgbeurs.nl/login
<table width="300">
<tr>
<td>
<asp:Label ID="UserNameLabel" Text="Email" runat="server" AssociatedControlID="UserName"/>
</td>
<td>
<asp:TextBox ID="UserName" Text="" runat="server" Width="160px"/><br />
<asp:RequiredFieldValidator Enabled="false" ValidationGroup="loginuser" Display="Dynamic" SetFocusOnError="True" ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="*"/>
<asp:RegularExpressionValidator ControlToValidate="UserName" ValidationGroup="loginuser" ErrorMessage="Ongeldig emailadres" ValidationExpression="<%$resources:glossary,regexValidEmail %>" ID="revUsername" runat="server" Display="Dynamic"/>
</td>
</tr>
<tr>
<td valign="top">
<asp:Label ID="PasswordLabel" Text="<%$ Resources:Glossary,Password%>" runat="server" AssociatedControlID="Password"/>
</td>
<td valign="top">
<asp:TextBox ID="Password" runat="server" TextMode="Password" Width="160px"/><br />
<asp:RequiredFieldValidator Enabled="false" SetFocusOnError="True" Display="Dynamic" ValidationGroup="loginuser" ID="PasswordRequired" runat="server" ControlToValidate="Password" ErrorMessage="*" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:ImageButton CausesValidation="true" ValidationGroup="loginuser" ID="LoginMember" meta:resourcekey="ibtnLogin" CommandName="Login" runat="server"/>
<asp:CheckBox TextAlign="Right" CssClass="cblist" Font-Bold="false" ID="RememberMe" runat="server" Text="<%$ Resources:Glossary,loginrememberme%>" /><br />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="FailureText" runat="server" ForeColor="Red" Font-Bold="true" EnableViewState="False"/>
</td>
</tr>
</table>
update
I also tried adding the ValidationExpression of revUsername expression directly in the code [-+.'\w]+#[-.\w]+\.[-.\w]+, but that does not help.
I can see the required validators working in your live site without making a postback.
Regarding the email's regular expression validator, it seems that your expression is not working properly. So, I suggest you to change your regular expression, try this one:
<asp:RegularExpressionValidator Enabled="true" ControlToValidate="UserName"
ValidationGroup="loginuser" ErrorMessage="Ongeldig emailadres"
ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"
ID="revUsername" runat="server" Display="Dynamic" />
Also, remember to enable it again in order to make it work both on client and server side.
Hope it can help you!
Related
I'm trying to create a custom web control, but I have limited experience with Web Forms. How do I access the text passed in between the open an close tags? The control should work like the this.
Usage
<asp:YesOrNoQuestion>Are you above the age of 18 ? </asp:YerOrNoQuestion>
Control
<tr id="trQ6CA" runat="server" visible="false">
<td>
<asp:Label ForeColor="Black" ID="QuestionLabel" runat="server">
// Question Goes Here
</asp:Label>
</td>
<td>
<asp:RadioButtonList ID="buttonCollection" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="Y">Yes</asp:ListItem>
<asp:ListItem Value="N">No</asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:RequiredFieldValidator ControlToValidate="buttonCollection" ID="Requiredfieldvalidator" InitialValue="" runat="server" Text="*" ValidationGroup="vgApplication">
*
</asp:RequiredFieldValidator>
</td>
</tr>
Code I'm Replacing
<tr id="trQ6CA" runat="server" visible="false">
<td valign="top" align="left">
<asp:Label ID="Label10" runat="server" ForeColor="Black">
<b>DOES THE PROPOSED INSURED:</b>
Have a comprehensive health benefits from an insurance policy, an HMO plan, or employer health benefit plan? <br />
If No, persons without such comprehensive coverage are not eligible for this insurance policy.
</asp:Label>
</td>
<td valign="top">
<asp:RadioButtonList ID="rbtQ6S1" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="Y">Yes</asp:ListItem>
<asp:ListItem Value="N">No</asp:ListItem>
</asp:RadioButtonList>
</td>
<td valign="top">
<asp:RequiredFieldValidator ID="Requiredfieldvalidator65" runat="server" Text="*" ControlToValidate="rbtQ6S1" InitialValue="" ValidationGroup="vgApplication">
*
</asp:RequiredFieldValidator>
</td>
</tr>
You can choose prefix and tag when you register the control:
https://msdn.microsoft.com/en-us/library/sbz9etab.aspx
It's not displaying the min requirement until the 'CreateUser' is clicked. How do I make it to validate the password requirement beforehand and display a message when the password field loses focus.
With the default markup of CreateUserWizard control as below, you cannot have such functionality.
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
Therefore, the idea is to customize the CreateUserWizard control as per your needs. Its better to use Validators so that you can display the messages beforehand. They key is to create a <ContentTemplate> element within the <asp:CreateUserWizardStep> element.
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
<ContentTemplate>
<table>
<tr>
<td>
Sign Up to get started</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>
<td>
<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>
</ContentTemplate>
</asp:CreateUserWizardStep>
Read MSDN for a complete tutorial.
I have a basic ASP.NET website which has a register page with the user name, password and email as text boxes. Only one of them, the email, has a validation which is the default email validation from ASP.NET.
After the validation, I want the cursor to be in the email textbox if the validation fails.
Currently the message is displayed but the cursor is not on the page.
<tr>
<td>
<asp:TextBox ID="txtPassword" runat="server" CssClass="cpTextBox" TextMode="Password"
TabIndex="7" ToolTip="Password must be at least six characters in length"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvPassword" runat="server" ControlToValidate="txtPassword"
ErrorMessage="Please enter password" Display="None">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revPassword" runat="server" ControlToValidate="txtPassword"
ErrorMessage="Password must be at least six characters in length" ValidationExpression=".{6,50}"
Display="None">*</asp:RegularExpressionValidator>
</td>
<td>
<asp:TextBox ID="txtTitle" runat="server" CssClass="cpTextBox" TabIndex="11"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblVerifyPassword" runat="server" CssClass="cpLabel" Text="Verify password"></asp:Label>
<asp:Label ID="Label4" runat="server" ForeColor="Red" Text="*"></asp:Label>
</td>
<td>
<asp:Label ID="lblPhone" runat="server" CssClass="cpLabel" Text="Phone"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtVerifyPassword" runat="server" CssClass="cpTextBox" TextMode="Password"
TabIndex="8"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvConfirmPassword" runat="server" ControlToValidate="txtVerifyPassword"
ErrorMessage="Please verify the password" Display="None">*</asp:RequiredFieldValidator>
<asp:CompareValidator ID="cvVerifyPassword" runat="server" ControlToCompare="txtPassword"
ControlToValidate="txtVerifyPassword" ErrorMessage="Please verify the password"
Display="None">*</asp:CompareValidator>
</td>
Can someone guide me on how to do this?
Regards.
For the validator control please set SetFocusOnError="true"
I have a few validation controls with a validationsummary.
The client side validations shows up, after the user leaves the textbox for the validation.
The server side validation shows never up.
The Validationsummary shows never up.
What I am doing wrong?
<div class="designPhotoMiddleText" id="MiddleReg" >
<asp:Panel DefaultButton="linkRegister" runat="server" ID="panRegister" >
Jetzt kostenlos registrieren:<br />
<br />
<table>
<tr>
<td style="width: 120px;">
Username:
</td>
<td>
<asp:TextBox ID="txtRegisterUsername" Width="150px" runat="server"></asp:TextBox>
<asp:CustomValidator ValidationGroup="Register" ID="valUsername" ControlToValidate="txtRegisterUsername"
OnServerValidate="IsUsernameFree" CssClass="validator"
runat="server" ErrorMessage="CustomValidator"></asp:CustomValidator>
</td>
</tr>
<tr>
<td>
Passwort:
</td>
<td>
<asp:TextBox ID="txtRegisterPW1" Width="150px" TextMode="Password" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ValidationGroup="Register" CssClass="validator" ControlToValidate="txtRegisterPW1" ID="valPasswordLenght" runat="server" ErrorMessage="Das Passwort muss mindestens 6 Zeichen haben."></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
Passwort erneut:
</td>
<td>
<asp:TextBox ID="txtRegisterPW2" Width="150px" TextMode="Password" runat="server"></asp:TextBox>
<asp:CompareValidator CssClass="validator" ValidationGroup="Register"
ID="valPW" ControlToCompare="txtRegisterPW2" ControlToValidate="txtRegisterPW1" runat="server" ErrorMessage="Die eingegebenen Passwörter stimmen nicht überein."></asp:CompareValidator>
</td>
</tr>
<tr>
<td>
Email:
</td>
<td>
<asp:TextBox ID="txtRegisterEmail" Width="150px" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ValidationGroup="Register" CssClass="validator" ForeColor="black"
ControlToValidate="txtRegisterEmail" ID="valMail" runat="server"
ValidationExpression=".*#.*\.(com|net|org|edu|mil|at?|de?|ch?|uk?)$"
ErrorMessage="Bitte geben Sie eine gültige EMail-Adresse ein."
Display="Dynamic"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:CheckBox ID="chkRegsiterAGBs" runat="server" />
<asp:HyperLink ID="linkAGB" Target="_blank" NavigateUrl="~/AGBs.aspx" runat="server">AGBs</asp:HyperLink> gelesen
<asp:CustomValidator ValidationGroup="Register" ID="valAGB"
OnServerValidate="IsAGBChecked" CssClass="validator"
runat="server" ErrorMessage="CustomValidator"></asp:CustomValidator>
</td>
</tr>
<tr>
<td colspan="2">
<asp:LinkButton CausesValidation="true" ID="linkRegister" CssClass="linkWhite" runat="server"
onclick="linkRegister_Click">Jetzt Registrieren</asp:LinkButton>
<asp:ValidationSummary ValidationGroup="Register" ID="sumRegister" runat="server"
HeaderText="Fehler:"
ShowSummary="true" DisplayMode="BulletList" />
</td>
</tr>
</table>
</asp:Panel>
</div>
public void IsUsernameFree(object source, ServerValidateEventArgs value)
{
string username = value.Value;
DAL.User user = DAL.UserHandling.GetUserByName(username);
value.IsValid = (user == null);
}
public void IsAGBChecked(object source, ServerValidateEventArgs value)
{
value.IsValid = (chkRegsiterAGBs.Checked);
}
Can't tell for sure from looking at the code you've posted, but are you checking the Page's IsValid property anywhere? E.g. before running any other methods?
if (Page.IsValid){
//Do additional processing
//register user etc.
}
this check will force execution of all validation controls on the page and should then trigger the display of your validation errors.
EDIT:
You need to set the ValidationGroup to 'Register' in your markup that defines the linkRegister control
`<asp:LinkButton CausesValidation="true" ID="linkRegister" CssClass="linkWhite" runat="server" OnClick="linkRegister_Click" ValidationGroup="Register">Jetzt Registrieren</asp:LinkButton>`
Also, your RegularExpressionValidator for password needs to have its ValidationExpression property set in the markup:
`<asp:RegularExpressionValidator ValidationGroup="Register"
CssClass="validator" ControlToValidate="txtRegisterPW1"
ID="valPasswordLenght" runat="server" ErrorMessage="Das Passwort
muss mindestens 6 Zeichen haben." Validationexpression="[\w+\d+]{6,}"
</asp:RegularExpressionValidator>`
i have a RegularExpressionValidator to validate an Email input that i have,
it works perfectly, if the input matches the Regular-expression,
However,if i enter a mistaken email it would show an error msg, if i fix the email in the input , it doesnt recheck it, the error msg stays not allowing me to click the Registeration button-or more like it gets clicked, but no event gets fired-
EDIT: added the ASPX code
< table width="100%">< tr><td>Username:</td>
<td>
<input runat="server" id="txtUsername" type="text" size="30" />
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="txtUsername" ErrorMessage="*"></asp:RequiredFieldValidator
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ErrorMessage="Username has to be atleast between 4-8 "
ValidationExpression="[A-Z]{4-8}"
ControlToValidate="txtUsername"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td> Email:</td><td>
<input runat="server" id="txtemail" type="text" size="30" /></td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtemail" ErrorMessage="*">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtemail" ErrorMessage="Format must be: abc#abc.com"
ValidationExpression="^[A-Za-z0-9._%+-]+#([A-Za-z0-9-]+\.)+([A-Za-z0-9]{2,4}|museum)$">
</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
<asp:Label runat="server" ForeColor="red" ID="lblerror"></asp:Label>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button runat="server" Text="Register"
ID="btnSubmit" Width="118px" onclick="btnSubmit_Click" />
</td>
</tr>
</table>
Are you checking for Page.IsValid in your btnSubmit_Click method?
Also your validation expression for username doesn't look correct, use a comma between your min and max lengths.
ValidationExpression="[A-Z]{4-8}"
ValidationExpression="[A-Z]{4,8}"