RequiredFieldValidator not firing, but RangeValidator is fine - asp.net

My RangeValidator is working perfectly. My RequiredFieldValidator is not firing at all. Any ideas why?
<asp:TextBox ID="txtTestNumber" runat="server" MaxLength="4"
Text='<%# eval("LC") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvTestNumber" runat="server"
Display="Dynamic" EnableClientScript="False" ErrorMessage="Required"
ForeColor="Red" ControlToValidate="txtTestNumber" Enabled="true"
ValidationGroup="WizStepValidationGroup">required
</asp:RequiredFieldValidator>
<asp:RangeValidator ValidationGroup="WizStepValidationGroup"
Display="Dynamic" ID="rvTestNumber" runat="server" ErrorMessage="Invalid value"
MinimumValue="0" MaximumValue="9999" ControlToValidate="txtTestNumber"
Type="Integer"></asp:RangeValidator>
Thanks for your input!

Add the ValidationGroup="WizStepValidationGroup" property to the text box and the button.
UPDATE:
You have set EnableClientScript="False" of RequiredFieldValidator hence it is not getting validated at the client side. Hence remove the EnableClientScript property or set it to True and I am 100% sure then it will work.

Related

RegularExpressionValidator in Asp.net

I have search textbox,which has default value Enter Month to View Profit. When I click search button without entering any data, the default value of textbox is posted to server for search. I want that RegularExpressionValidator do not validate default value of textbox.
<asp:TextBox ID="Tboxsearch" Text="Enter Month to View Profit" OnClick="this.value=''" CssClass="textboxinput" runat="server"></asp:TextBox>
<asp:Button ID="ButtonSearch" CssClass="btnLog" runat="server" Text="Search" onclick="ButtonSearch_Click" />
<asp:RequiredFieldValidator
ID="RequiredFieldValidatorname"
runat="server"
ControlToValidate="Tboxsearch"
ForeColor="Red"
Text="*"
>
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator
ID="RegularExpressionValidatorname"
runat="server"
ValidationExpression="[a-zA-Z0-9]+"
ForeColor="Red"
ControlToValidate="Tboxsearch"
ErrorMessage="Enter Valid Name!"
>
</asp:RegularExpressionValidator>
The default for all validators except the RequiredFieldValidator control if you post with empty field the validator will not trigger
you must use required field validator with other validators to prevent the postback to happen
from MSDN
Special-Case Validation Results for ASP.NET Server Controls
EDIT
Also if you add your controls as in your question it should work but if there is other controls like for example other button you should set the validationGroup Property to the group that you want to work together
ValidationGroup="vGrp"
and your code will be like this
<asp:TextBox ID="Tboxsearch" Text="Enter Month to View Profit" OnClick="this.value=''" CssClass="textboxinput" runat="server" ValidationGroup="vGrp"></asp:TextBox>
<asp:Button ID="ButtonSearch" CssClass="btnLog" runat="server" Text="Search" onclick="ButtonSearch_Click" ValidationGroup="vGrp" />
<asp:RequiredFieldValidator
ID="RequiredFieldValidatorname"
runat="server"
ControlToValidate="Tboxsearch"
ForeColor="Red"
Text="*"
ValidationGroup="vGrp">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator
ID="RegularExpressionValidatorname"
runat="server"
ValidationExpression="[a-zA-Z0-9]+"
ForeColor="Red"
ControlToValidate="Tboxsearch"
ErrorMessage="Enter Valid Name!" ValidationGroup="vGrp"></asp:RegularExpressionValidator>
from MSDN about validationGroup

Prevent textbox from firing validators

So I have a textbox with 6 validators. 2 of each kind because I have two validation groups depending on what button the user clicks. My problem is everytime the textbox loses focus two error messages get displayed, and this looks wierd. I've tried setting the CausesValidation property of the textbox to "false" but it's not working.
Textbox & Validators -
<asp:TextBox ID="collectionDtl_Qty" runat="server" CssClass="formText"
AutoPostBack="false" CausesValidation="false" Text="0">
</asp:TextBox>
<asp:FilteredTextBoxExtender ID="collectionDtl_Qty_Filtered" runat="server"
FilterMode="ValidChars" TargetControlID="collectionDtl_Qty" ValidChars="1234567890,">
</asp:FilteredTextBoxExtender>
<asp:CustomValidator ControlToValidate="collectionDtl_Qty" ID="collectionDtl_Qty_CValidator"
runat="server" ClientValidationFunction="coll_QtyValidator"
Text="Quantity cannot be greater than requested quantity." ForeColor="Red"
ValidationGroup="formValidation" Display="Dynamic">
</asp:CustomValidator>
<asp:CustomValidator ControlToValidate="collectionDtl_Qty" ID="collectionDtl_Qty_CValidator2"
runat="server" ClientValidationFunction="coll_QtyValidator"
Text="Quantity cannot be greater than requested quantity." ForeColor="Red"
ValidationGroup="detailValidation" Display="Dynamic">
</asp:CustomValidator>
<asp:CompareValidator ControlToValidate="collectionDtl_Qty" ID="collectionDtl_Qty_Comparer"
runat="server" Text="Quantity must be greater than 0." ForeColor="Red"
ValidationGroup="formValidation" Display="Dynamic"
ValueToCompare="0" Operator="GreaterThan" Type="Integer">
</asp:CompareValidator>
<asp:CompareValidator ControlToValidate="collectionDtl_Qty" ID="collectionDtl_Qty_Comparer2"
runat="server" Text="Quantity must be greater than 0." ForeColor="Red"
ValidationGroup="detailValidation" Display="Dynamic"
ValueToCompare="0" Operator="GreaterThan" Type="Integer">
</asp:CompareValidator>
Any help would be appreciated.
Hi according to your question.what i understand you have to disabled validator or use validation based on Button click.
For Button click use ValidationGroup
ValidationGroup="save"
If you want to disabled validators on condition .Try this one
ValidatorEnable(document.getElementById('<%= rqrgvddlCategory.ClientID %>'), false);
Hope it will helps you.

RegularExpressionValidator shows an exception that following field cannot be empty

I have a textbox txtemailid which has two validator RequiredFieldValidator and RegularExpressionValidator as:
<asp:TextBox ID="txtEMailId" CssClass="Text1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RFVtxtEMailId"
runat="server"
ErrorMessage="*"
Display="Dynamic"
ForeColor="Red"
ControlToValidate="txtEMailId"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="REVtxtEMailId"
runat="server"
ValidationExpression="\w+([-+.]\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"
Display="Dynamic"
ErrorMessage="Invalid Email Format"
ForeColor="Red"></asp:RegularExpressionValidator>
it shows following error
The ControlToValidate property of 'REVtxtEMailId' cannot be blank.
You not have specified which control should be validated .Try this
<asp:RegularExpressionValidator ID="REVtxtEMailId"
runat="server"
ValidationExpression="\w+([-+.]\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"
Display="Dynamic"
ErrorMessage="Invalid Email Format"
ForeColor="Red" ControlToValidate="txtEMailId"></asp:RegularExpressionValidator>
You have not provided ControlTo Validate Property in Regular Expression Validator.Add this property in REVtxtEMailId

ASP.NET: ValidationSummary doesn't display any contents

I'm trying to figure out how the heck the validation summary control of ASP.NET (3.5 I think) works.
<asp:ValidationSummary ID="vldSummary" runat="server" DisplayMode="BulletList"
CssClass="error" EnableClientScript="true" />
<asp:RequiredFieldValidator ID="vldSubject" ControlToValidate="txtSubject"
EnableClientScript="false" Text="You must enter a subject." runat="server" />
<asp:RequiredFieldValidator ID="vldMessage" ControlToValidate="txtMessage"
EnableClientScript="false" runat="server" Text="You must enter a message." />
It seems that no matter what I do, the validation summary remains empty (but is rendered) and the errors are only displayed at the position of each respective validator.
What am I doing wrong?
Text property's value is what is displayed beside the control. You need to set the ErrorMessage property of the validators to control what is shown in the summary.
You want to set the ErrorMessage property on your validation controls. This text will be displayed by the ValidationSummary control.
Try:
<asp:ValidationSummary ID="vldSummary" runat="server" DisplayMode="BulletList" CssClass="error" EnableClientScript="true" />
<asp:RequiredFieldValidator ID="vldSubject" ControlToValidate="txtSubject" EnableClientScript="false" ErrorMessage="You must enter a subject." runat="server" />
<asp:RequiredFieldValidator ID="vldMessage" ControlToValidate="txtMessage" EnableClientScript="false" runat="server" ErrorMessage="You must enter a message." />
Set the ErrorMessage property on the RequiredFieldValidators, not the Text property.
<asp:RequiredFieldValidator ID="vldSubject" ControlToValidate="txtSubject" EnableClientScript="false" ErrorMessage="You must enter a subject." runat="server" />
<asp:RequiredFieldValidator ID="vldMessage" ControlToValidate="txtMessage" EnableClientScript="false" runat="server" ErrorMessage="You must enter a message." />

Required+regular validation

<asp:TextBox ID="Textboxtotalamount"
OnTextChanged="AmountChanged"
Width="90px"
AutoPostBack="true"
runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator"
runat="server"
ControlToValidate="Textboxtotalamount"
SetFocusOnError="True"
ValidationGroup="val">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server"
ControlToValidate="Textboxtotalamount"
ValidationExpression="^[-+]?[1-9]\d{0,13}(\.\d{1,3})?%?$"
SetFocusOnError="True">F</asp:RegularExpressionValidator>
in this above code can validate correctly.......but in text box i call "OnTextChanged"
event ....suppose if i type(characters)in textbox errormesge shown at the same time ontextchanged event also called hen error occured ....i ve to stop OnTextChanged event when regularexpression raised......
pls help
try this
<asp:TextBox ID="Textboxtotalamount" OnTextChanged="AmountChanged" Width="90px" AutoPostBack="true"
CausesValidation="true" ValidationGroup="val" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator" runat="server" ControlToValidate="Textboxtotalamount"
SetFocusOnError="True" ValidationGroup="val">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="Textboxtotalamount" ValidationGroup="val"
ValidationExpression="^[-+]?[1-9]\d{0,13}(\.\d{1,3})?%?$" SetFocusOnError="True">F</asp:RegularExpressionValidator>
i've added. the CausesValidation="true" and ValidationGroup="val" to the TextBox.
and ValidationGroup="val" to the RegularExpressionValidator
now the OnTextChanged will only fire when all the validators in the group "val" succeed

Resources