Click here to Skip to main content
12,509,269 members (55,997 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
i have a login page.
i am using asp.net requiredfieldvalidtaor and reularexpression validator on the same textbox.

The problem is that ,only requiredfield validator is getting fired. and not the regular expression.


For Example:

email: left empty.hence requiredfield will fire


email: abc@dfbmw regularexpression will not fire.





Both are working fine if used seperatly but when used together,the problem arises.
Posted 1-Feb-13 0:25am
Comments
AdityaPratapSingh 1-Feb-13 6:48am
   
write your code here
Lakshmimsridhar 1-Feb-13 7:27am
   
ya put your code here so that we can tell u
Nandakishorerao 1-Feb-13 7:39am
   
make both into a single validation group.
Member 9581909 4-Feb-13 2:20am
   
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">


<asp:Panel ID="LoginPanel" runat="server" Width="500px" Height="650px"
BorderColor="#00CC66" BorderStyle="Inset" BackColor="ActiveCaption"
style="position: relative; top: 5px; left: 1065px">
<asp:Label ID="Label1" runat="server" Text="User Name"
style="z-index: 1; left: 58px; top: 170px; position: absolute"
Font-Size="X-Large" Font-Bold="True">
<asp:Label ID="Label2" runat="server" Text="Password"
style="z-index: 1; left: 60px; top: 221px; position: absolute"
Font-Size="X-Large" Font-Bold="True">
<asp:TextBox ID="TxtUserName" runat="server" ValidationGroup="ValGroup1"

style="position: absolute; z-index: 1; left: 193px; top: 171px; height: 21px; width: 197px;"
TabIndex="1" EnableViewState="False" CausesValidation="True"
>

<asp:Label ID="Label6" runat="server" Text="*" Font-Bold="True"
Font-Size="Medium" ForeColor="#CC3300"
style="z-index: 1; left: 49px; top: 166px; position: absolute">
<asp:Label ID="Label7" runat="server" Text="*" ForeColor="#CC3300"
style="z-index: 1; left: 51px; top: 219px; position: absolute">
<asp:RequiredFieldValidator ID="RequiredFieldValidatorUserName" runat="server"
ErrorMessage="The fields marked with asterisk(*) are mandatory" ControlToValidate="TxtUserName"
style="z-index: 1; left: 136px; top: 131px; position: absolute"
ValidationGroup="ValGroup1">

<asp:Button ID="Button1"
runat="server" Text="Log In"
style="z-index: 2; left: 194px; top: 290px; position: absolute" OnClientClick="return checkforlength();"
onclick="Button1_Click" ValidationGroup="ValGroup1"
CausesValidation="True" />
<asp:HyperLink ID="HyperLink2" runat="server"
style="z-index: 1; left: 194px; top: 383px; position: absolute"
TabIndex="4" Font-Names="Arial" Font-Size="Large"
NavigateUrl="~/ForgotPwd.aspx">Forgot Password?

<asp:HyperLink ID="HyperLink1" runat="server" Font-Bold="True"
Font-Names="Arial" Font-Size="Large" Font-Underline="True"
style="z-index: 1; left: 295px; top: 52px; position: absolute"
NavigateUrl="~/CreateYourAccount.aspx">Create your Account


<asp:TextBox ID="TxtPassword" runat="server" ValidationGroup="ValGroup1"

style="z-index: 1; left: 192px; top: 223px; position: absolute; height: 21px; width: 195px;"
TabIndex="2" EnableViewState="False" TextMode="Password"
ToolTip="This Field is case sensitive." CausesValidation="True">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="The fields marked with asterisk(*) are mandatory"
ControlToValidate="TxtPassword" ValidationGroup="ValGroup1"
style="z-index: 1; left: 136px; top: 131px; position: absolute">

<asp:Label ID="Label3" runat="server" Text="Sign In"
Font-Bold="True" Font-Names="Century Gothic" Font-Overline="True"
Font-Underline="True" BackColor="ActiveCaption" Font-Size="X-Large"
style="z-index: 1; left: 57px; top: 48px; position: absolute">
<asp:Label ID="Label8" runat="server" Text="Incorrect UserId or Password" Font-Bold="True"
ForeColor="#CC3300"

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Refer this links...

for better understanding about validations.

http://www.w3schools.com/aspnet/aspnet_refvalidationcontrols.asp[^]
Understanding ASP.NET Validation Techniques[^]

I think in your case as per "Nandakishorerao" comment , you forgot to set validation group property once checkout that .
  Permalink  
v2
Comments
Member 9581909 2-Feb-13 5:58am
   
i put both of them to same validation group.
naveensenagasetti 2-Feb-13 6:21am
   
once post your code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160927.1 | Last Updated 2 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100