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.
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
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!
I'm using this code to validate two date but the validation is not working when I enter the same or after the Start Date
<asp:CompareValidator ID="dateCompareValidator" runat="server"
ControlToValidate="EndDate"
ControlToCompare="StartDate"
Operator="GreaterThanEqual" Type="Date"
ErrorMessage="The second date must be after the first one.<br /><br />">
</asp:CompareValidator>
Do i need to use the hard code ?
Aspx File:
<tr>
<td align="right">
Start Date:
</td>
<td align="left">
<telerik:RadDatePicker ID="RadDtpFromDate" runat="server" Calendar-EnableShadows="true" AutoPostBack="true"
Culture="en-IN" DateInput-DateFormat="dd-MMM-yyyy" DateInput-EmptyMessage="DD-MMM-YYYY"
ShowPopupOnFocus="true" ToolTip="Input Date" ZIndex="30001"
onselecteddatechanged="RadDtpFromDate_SelectedDateChanged" />
<asp:RequiredFieldValidator runat="server" ID="rfvFromDate" Display="None" ControlToValidate="RadDtpFromDate"
InitialValue="" ValidationGroup="FinalSave" ErrorMessage="From Date is Mandatory"
ForeColor="Red"></asp:RequiredFieldValidator>
<ajaxToolkit:ValidatorCalloutExtender ID="vceFromDate" TargetControlID="rfvFromDate"
runat="server">
</ajaxToolkit:ValidatorCalloutExtender>
<asp:CustomValidator ID="cvFromDate" runat="server" ControlToValidate="RadDtpFromDate"
Display="None"></asp:CustomValidator>
<ajaxToolkit:ValidatorCalloutExtender ID="vceRadFromDate" runat="server" TargetControlID="cvFromDate">
</ajaxToolkit:ValidatorCalloutExtender>
</td>
<td align="right">
End Date:
</td>
<td align="left" colspan="2">
<telerik:RadDatePicker ID="RadDtpToDate" runat="server" Calendar-EnableShadows="true" AutoPostBack="true"
Culture="en-IN" DateInput-DateFormat="dd-MMM-yyyy" DateInput-EmptyMessage="DD-MMM-YYYY"
ShowPopupOnFocus="true" ToolTip="Input Date" ZIndex="30001"
onselecteddatechanged="RadDtpToDate_SelectedDateChanged" />
<asp:RequiredFieldValidator runat="server" ID="rfvToDate" Display="None" ControlToValidate="RadDtpToDate"
InitialValue="" ValidationGroup="FinalSave" ErrorMessage=" To Date is Mandatory"
ForeColor="Red"></asp:RequiredFieldValidator>
<ajaxToolkit:ValidatorCalloutExtender ID="vceToDate" TargetControlID="rfvToDate"
runat="server">
</ajaxToolkit:ValidatorCalloutExtender>
<asp:CustomValidator ID="cvToDate" runat="server" ControlToValidate="RadDtpToDate"
Display="None"></asp:CustomValidator>
<ajaxToolkit:ValidatorCalloutExtender ID="vceRadToDate" runat="server" TargetControlID="cvToDate">
</ajaxToolkit:ValidatorCalloutExtender>
</td>
</tr>
Cs File :
if (RadDtpFromDate.SelectedDate > RadDtpToDate.SelectedDate)
{
dateCompareValidator.IsValid = False;
return;
}
Now Try this..................
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 am using two panels (login and registration) in asp.net where in both panels i used button control. and i also used validations for particular textboxes in both panels.
i want to show both panels at same time.
now what problem i am facing is that when i click on button of login panel, it shows validation error text in registration panel and vice-versa..
Is there nay other way to use any other control instead of button.
i am using visual studio-2008
i had created login panel as:
<asp:Panel ID="pnllogin" runat="server">
<table class = "style1">
<tr>
<td>
<asp:Label ID="lblloginid" runat="server" Text="Login_ID" Font-Bold="true"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtboxloginid" runat="server" ></asp:TextBox>
<asp:RequiredFieldValidator ID="requiredfieldvalidator1" runat="server"
ControlToValidate="txtboxloginid" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblpassword" runat="server" Text="Password" Font-Bold="true"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtboxpassword" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="requiredfieldvalidator2" runat="server"
ControlToValidate="txtboxpassword" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:HyperLink ID="hyperlinkforgotpassword" runat="server" ForeColor="Red" NavigateUrl="~/ForgotPassword.aspx">Forgot Password??</asp:HyperLink>
</td>
</tr>
<tr>
<td> </td>
<td>
<asp:ImageButton ID="imgbtnlogin" runat="server" ImageUrl="~/images/login.png"
onclick="imgbtnlogin_Click" />
</td>
</tr>
</table>
</asp:Panel>
and somewhat same code for registration panel..
can someone please help me..
Make use of ValidationGroup property to fire the validation message related to proper panel
here is detail info : http://www.w3schools.com/ASPNET/prop_webcontrol_imagebutton_validationgroup.asp
demo : http://www.w3schools.com/ASPNET/showasp.asp?filename=demo_prop_webcontrol_imagebutton_validationgroup
Specifying Validation Groups