I have used compare validator to check whether the selected date is valid or it. The issue here is it only fires up when the submit button is clicked, is it possible to check when the user selects the date.
<tr id="trow" runat="server">
<td class="auto-style3">Need Duration</td>
<td class="auto-style2">
<asp:TextBox ID="TextBox1" runat="server" ReadOnly = "true"></asp:TextBox>
<asp:ImageButton ID="imgJoin" runat="server" ImageUrl="Images/calender.png"/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="TextBox1" ErrorMessage="*" ForeColor="Red"
SetFocusOnError="True"></asp:RequiredFieldValidator></td>
<td>
<asp:TextBox ID="TextBox2" runat="server" ReadOnly = "true"></asp:TextBox>
<asp:ImageButton ID="imgHide" runat="server" ImageUrl="Images/calender.png"/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server"
ControlToValidate="TextBox2" ErrorMessage="*" ForeColor="Red"
SetFocusOnError="True"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator1" runat="server" Operator="GreaterThanEqual"
ControlToValidate="TextBox2" ControlToCompare="TextBox1"
ErrorMessage='Invalid Date'
ForeColor="Red"></asp:CompareValidator>
</td>
</tr>
It has been a while, but I think you need to enable client side validation scripts by adding:
EnableClientScript="True"
Example
<asp:CompareValidator ID="CompareValidator1" EnableClientScript="True" runat="server"
Operator="GreaterThanEqual"
ControlToValidate="TextBox2" ControlToCompare="TextBox1"
ErrorMessage='Invalid Date'
ForeColor="Red"></asp:CompareValidator>
It's documented at msdn.
Aditionally, I do know that custom validators often lack a correct implementation of the javascript. I am not sure how the CompareValidatorbehaves in that sense.
You might need to create a inherited class, to implement the scripts fully. Before going there, try do research a bit.
For example, here is a solution with a custom validator
Related
I have the following asp code:
<asp:TextBox ID="txtNewPassword" TextMode="Password" Placeholder="New Password" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorNewPassword"
runat="server" ErrorMessage="New Password required" ControlToValidate="txtNewPassword" ForeColor="Red">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ErrorMessage="Password must be at least 6 characters long" ForeColor="Red" ControlToValidate="txtNewPassword"
ValidationExpression="[0-9a-zA-Z]{6,}"/>
The thing is that they are hidden in visibiliy and not in display when not required, but that is a problem because they take space nonetheless.
I have a form for adding some values to my DB. One of the input requires a Integer value, so on that TextBox I have two validators, an RequiredFieldValidator and an CompareValidator. The problem is that when I click on the input the first time ( or I got there with tab) the error message is displayed an it will never disappear, even if I enter a valid input.
<asp:Label ID="label4" runat="server" Text="label4"></asp:Label>
<asp:TextBox ID="textBox4" runat="server" style="width: 170px; margin: 5px 0;"></asp:TextBox>
<asp:RequiredFieldValidator ID="requiredFieldValidator4" runat="server"
ErrorMessage="*" ControlToValidate="textBox4" Display="Dynamic"
ForeColor="Red" ValidationGroup="1"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="compareValidator4" runat="server"
ErrorMessage="*" ControlToValidate="textBox4"
Type="Integer" Operator="DataTypeCheck" Display="Dynamic"
ForeColor="Red" ValidationGroup="1">
</asp:CompareValidator>
Above is my code for that input.
Have you already tried adding the property "ControlToCompare" to your compare validator?, for reference take a look of this post: http://forums.asp.net/t/1842937.aspx?CompareValidator+doesn+t+disappear+when+entering+the+correct+value
Thank you very much for taking the time to read this. I have an issue in which I was setting a default button for an ASP.NET page on page load from code behind, but now that I have multiple validation groups targeting one control, that is no longer working. Now, when I hit enter while in that control (textbox), validation for both groups are triggered minus the validation summary text.
Here is my examplefied code:
ASPX
<table>
<tr>
<td><asp:Textbox runat="server" ID="validateMe"></asp:TextBox></td>
<td><asp:RequiredFieldValidator ID="firstValidator" runat="server" ErrorMessage="First check not valid" Text="*" ControlToValidate="validateMe" ValidationGroup="firstGroup"></asp:RequiredFieldValidator>
<td><asp:RequiredFieldValidator ID="secondValidator" runat="server" ErrorMessage="Second check not valid" Text="*" ControlToValidate="validateMe" ValidationGroup="secondGroup"></asp:RequiredFieldValidator>
</tr>
<tr>
<td><asp:Button runat="server" ID="firstButton" Text="V1" ValidationGroup="firstGroup"/></td>
<td><asp:Button runat="server" ID="secondButton" Text="V2" ValidationGroup="secondGroup"/></td>
</tr>
<table>
<asp:ValidationSummary ID="firstSummary" runat="server" ValidationGroup="firstGroup"/>
<asp:ValidationSummary ID="secondSummary" runat="server" ValidationGroup="secondGroup"/>
C#
protected void Page_Load(object sender, EventArgs e)
{
this.Form.DefaultButton = firstButton.UniqueID;
}
If I use this and hit 'Enter' while inside of the textbox without typing anything into it, then neither of the validation summaries will appear but I will have two asterisks next to the textbox (one for each group). If the user presses 'Enter' I would expect a full validation using only the first group which is supposed to be assigned to the DefaultButton (here, 'firstButton'). Is there any way to achieve this functionality and initiate the client-side validation that would have happened had the user clicked 'firstButton' instead?
I have also tried wrapping the whole table plus the validation summaries inside of an asp:Panel and setting the DefaultButton there, but I received the same results. Any help or pointers in the right direction would be greatly appreciated!
Set
EnableClientScript="false"
in RequiredFieldValidator control. It will help.
<asp:Panel runat="server" DefaultButton="secondButton">
<table>
<tr>
<td>
<asp:TextBox runat="server" ID="validateMe"></asp:TextBox></td>
<td>
<asp:RequiredFieldValidator ID="firstValidator" runat="server" ErrorMessage="First check not valid" Text="*" ControlToValidate="validateMe" EnableClientScript="false" ValidationGroup="firstGroup"></asp:RequiredFieldValidator>
</td>
<td>
<asp:RequiredFieldValidator ID="secondValidator" runat="server" ErrorMessage="Second check not valid" Text="*" ControlToValidate="validateMe" EnableClientScript="false" ValidationGroup="secondGroup"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Button runat="server" ID="firstButton" Text="V1" ValidationGroup="firstGroup" /></td>
<td>
<asp:Button runat="server" ID="secondButton" Text="V2" ValidationGroup="secondGroup" /></td>
</tr>
</table>
<asp:ValidationSummary ID="firstSummary" runat="server" ValidationGroup="firstGroup" />
<asp:ValidationSummary ID="secondSummary" runat="server" ValidationGroup="secondGroup" />
</asp:Panel>
I have a captcha control, when write code and check it it always be wrong if I write it correctly , then form the second time it works fine.
what may be the problem in that
that is the captcha
<td id="Td6" runat="server" align="center" class="style4">
<MSCapatchaControl:CaptchaControl ID="Capatcha"
runat="server"
BackColor="#CC3300"
CaptchaBackgroundNoise="Extreme"
CaptchaChars="ACDEFGHJKLNPQRTUVXYZ2346789"
CaptchaHeight="40"
CaptchaMaxTimeout="240"
CaptchaMinTimeout="5"
CaptchaWidth="130"
FontColor="White"
ForeColor="White"
LineColor="Black"
NoiseColor="Black" />
</td>
<td id="Td7" runat="server" colspan="3">
<asp:TextBox ID="registerCaptchText"
runat="server" MaxLength="6" Width="135px">
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server"
ControlToValidate="registerCaptchText"
Display="None"
ErrorMessage="Enter the capatcha">
</asp:RequiredFieldValidator>
<font style="font-size:12px; font-family:trebuchet; color: rgb(51, 51, 51);">
<div class="important">*</div>
Please enter the text you see in the image.
</font>
</td>
and that is the function test it
Capatcha.ValidateCaptcha(registerCaptchText.Text);
bool capatchaValid = Capatcha.UserValidated;
Hi I have solved this problem by taken captcha field in update panel.
Thanks Every one for your value able time.
I want use a RegularExpressionValidator for a date in this form yyyy-mm-dd (example: 2012-11-29) and here is my expresion:
/^(19[789]\d|20[0123]\d)-(0\d|1[012]|\d)-(31|30|[012]\d|\d)$/
I test it on http://www.quanetic.com/Regex and it works but if I do this in my asp.net application it doesn't work
<tr>
<td>Gültig ab:</td>
<td><asp:TextBox ID="txtVon" runat="server" ></asp:TextBox></td>
<td><asp:ImageButton ID="imgVon" runat="server" ImageUrl="images/Calender.ico" Width="15" Height="15" />
<asp:CalendarExtender runat="server" ID="E_Von" TargetControlID="txtVon" Format="yyyy-MM-dd" PopupButtonID="imgVon"/></td>
<td>
<asp:RequiredFieldValidator ID="ValVon"
runat="server" ForeColor="red"
ErrorMessage="*" ControlToValidate="txtVon"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regVon"
runat="server" ControlToValidate="txtVon"
ErrorMessage="*Format" ForeColor="red"
ValidationExpression="/^(19[789]\d|20[0123]\d)\-(0\d|1[012]|\d)\-(31|30|[012]\d|\d)$/"></asp:RegularExpressionValidator>
</td>
</tr>
Where is the error?
Just remove char "/" in the begining and in the and of the string.
And you will have
ValidationExpression="^(19[789]\d|20[0123]\d)-(0\d|1[012]|\d)-(31|30|[012]\d|\d)$"
I use the following, which works ok.
\A(?:^(19|20)\d\d([- /.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])$)\Z