Reputation: 595
I'm using 3 validators to validate the TextBox, but all get triggered when invalid value is entered in the Textbox. But I want to these validators to work in a particular order so that users can resolve these faults one by one.
<asp:TextBox ID="txt_temp" runat="server"></asp:TextBox>
<asp:CompareValidator ID="cv_txt_temp" runat="server" CssClass="error" ControlToValidate="txt_temp" ValueToCompare="0" Type="Double" Operator="GreaterThanEqual" ValidationGroup="insert" SetFocusOnError="true" ErrorMessage="Must be valid value" Display="Dynamic"></asp:CompareValidator>
<asp:RegularExpressionValidator ID="rev_txt_temp" CssClass="error" SetFocusOnError="true"
runat="server" ErrorMessage="Value upto 1 decimal place" Display="Dynamic" ControlToValidate="txt_temp" ValidationExpression="\d+(?:(?:\.|,)\d{0,1})?" ValidationGroup="insert"></asp:RegularExpressionValidator>
<asp:RangeValidator ID="rv_txt_temp" Display="Dynamic" runat="server" SetFocusOnError="true" ValidationGroup="insert" ControlToValidate="txt_temp" Type="Double" CssClass="error"></asp:RangeValidator>
Upvotes: 8
Views: 4384
Reputation: 895
You can create your custom Validation. It will takes time, but you can control order of validation. You can also use masked textbox extender.
Upvotes: 0
Reputation: 125
My solution of "setting validation order" is: On Page where have validators: 1) I set AutoEventWireup to false in aspx code and use custom validators 2) I create and call functions for validations and sett "IsValid" for related validators:
validCustom1.IsValid = Validation1(textbox1.Text);
if (Page.IsValid)
validCustom2.IsValid = Validation2(textbox2.Text);
if (Page.IsValid)
validCustom3.IsValid = Validation3(textbox3.Text);
if (Page.IsValid)
{
//Do somethink
}
else
{
//Do somethink else
}
Upvotes: 0
Reputation: 561
You can use Custom Validator, Custom Java Script or Mask edit validator
Upvotes: 0
Reputation: 71
You can try with only RegularExpressionValidator
<asp:RegularExpressionValidator ID="rev_txt_temp" CssClass="error" SetFocusOnError="true"
runat="server" ErrorMessage="Error.." Display="Dynamic" ControlToValidate="txt_temp"
ValidationExpression="^[1-9]\d*(\.\d{0,1})?$" ValidationGroup="insert">
</asp:RegularExpressionValidator>
let me know, if you want in other way..
Upvotes: 0
Reputation: 1063
The validators that you add automatically add themselves to Page.Validators collection in the order they are created. The validation runs thorugh in the order they are present in the Page.Validators collection which means the first validator definition shown in the aspx file is first in Page.Validators. If you want to change the order, then the only way is to get all of your validators into the page in the order you want them to fire.
Edit : In your case the only way is to use css to overlap the validators.
Upvotes: 5