Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set the order of asp.net validator

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> 
like image 937
Arjun Sharma Avatar asked Jan 25 '13 06:01

Arjun Sharma


1 Answers

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.

like image 195
Srinivas Avatar answered Oct 12 '22 16:10

Srinivas