nithin raj

nithin raj

  • NA
  • 52
  • 463

single textbox with different validation

May 29 2018 5:48 AM
  1. <div class="search-container">  
  2. <label>  
  3. <br />  
  4. <br />  
  5. <br />  
  6. Sort By</label>  
  7.              
  8. <asp:TextBox ID="txtsearch" runat="server" placeholder="Search by Product Name/Brand Name/Product Description...." Width="460px"></asp:TextBox>  
  9.              
  10. Price Min : <asp:TextBox ID="txtminprice" ValidationGroup="productvalidate" runat="server"></asp:TextBox>  
  11. Max : <asp:TextBox ID="txtmaxprice" ValidationGroup="productvalidate" runat="server"></asp:TextBox>  
  12. <asp:CustomValidator ID="CustomValidator1" runat="server" Display="Dynamic" ErrorMessage="CustomValidator" ForeColor="Red" ValidationGroup="productvalidate" OnServerValidate="CustomValidator_ServerValidate"></asp:CustomValidator>  
  13. <asp:CompareValidator ID="CompareValidator1" ForeColor="Red" runat="server" Display="Dynamic" ControlToValidate="txtmaxprice" ValidationGroup="productvalidate" ControlToCompare="txtminprice" operator="GreaterThan" type="Double" ErrorMessage="max price must be grater than"></asp:CompareValidator>  
  14. <br /> <br />  
  15. Date From : <asp:TextBox ID="txtdatefrom" autocomplete="off" runat="server"></asp:TextBox>  
  16. <cc1:CalendarExtender ID="CalendarExtender1" Format="yyyy-M-dd" TargetControlID="txtdatefrom" runat="server"></cc1:CalendarExtender>  
  17. Date To : <asp:TextBox ID="txtdateto" autocomplete="off" runat="server"></asp:TextBox>  
  18. <cc1:CalendarExtender ID="CalendarExtender2" TargetControlID="txtdateto" Format="yyyy-M-dd" runat="server"></cc1:CalendarExtender>  
  19. <asp:CustomValidator ID="CustomValidator2" runat="server" Display="Dynamic" ErrorMessage="CustomValidator" ForeColor="Red" ValidationGroup="productvalidate" OnServerValidate="CustomValidator_ServerValidate1"></asp:CustomValidator>  
  20. <asp:CompareValidator ID="CompareValidator2" runat="server" ControlToValidate="txtdateto" Display="Dynamic" ValidationGroup="productvalidate" ForeColor="Red" ControlToCompare="txtdatefrom" operator="GreaterThan" type="Date" ErrorMessage="toDate must be grater than"></asp:CompareValidator>  
  21. <asp:CustomValidator ID="CustomValidator3" runat="server" ErrorMessage="CustomValidator" ForeColor="Red" Display="Dynamic" ValidationGroup="productvalidate" OnServerValidate="CustomValidator_ServerValidate2"></asp:CustomValidator>  
  22. <asp:ImageButton ID="btnsearchs" style="float:right" OnClick="btnsearchs_Click" Height="60px" ValidationGroup="productvalidate" runat="server" ImageUrl="~/Images/btnsearch.png" />  
  23. </div>  
  1. public void CustomValidator_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)  
  2. {  
  3. args.IsValid = true;  
  4. if ((txtminprice.Text != "" && txtmaxprice.Text == "") || (txtminprice.Text == "" && txtmaxprice.Text != ""))  
  5. {  
  6. CustomValidator1.ErrorMessage = "Enter value in at Both text Box";  
  7. args.IsValid = false;  
  8. }  
  9. }  
  10. public void CustomValidator_ServerValidate1(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)  
  11. {  
  12. args.IsValid = true;  
  13. if ((txtdatefrom.Text != "" && txtdateto.Text == "") || (txtdatefrom.Text == "" && txtdateto.Text != ""))  
  14. {  
  15. CustomValidator2.ErrorMessage = "Enter value in at Both text Box";  
  16. args.IsValid = false;  
  17. }  
  18. }  
  19. public void CustomValidator_ServerValidate2(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)  
  20. {  
  21. args.IsValid = true;  
  22. if ((txtdatefrom.Text == "" && txtdateto.Text == "") && (txtminprice.Text == "" && txtmaxprice.Text == "") && (txtsearch.Text==""))  
  23. {  
  24. CustomValidator3.ErrorMessage = "Select atleast one selection";  
  25. args.IsValid = false;  
  26. }  
  27. }  
this is my code ,the problem is after showing error message ,reenter correct input but it always shown, after button click is working fine, please tell solution of this problem

Answers (1)