Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 941657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:09:03+00:00 2026-05-15T22:09:03+00:00

I have a webform with two custom validators: One to validate that a string

  • 0

I have a webform with two custom validators:

  • One to validate that a string is a date. I don’t care what format, so long as it’s parseable.
  • Another to ensure that one date is equal to or greater than another. I just couldn’t get the compare validator to play nice with any date format.
<asp:TextBox ID="txtResourceStartDate" runat="server"
    CssClass="textBox mandatory dateField" />
<asp:CustomValidator ID="valResourceStartDateIsDate" runat="server"
    ControlToValidate="txtResourceStartDate" Display="None"
    ErrorMessage="Start date must be a valid date"
    OnServerValidate="Date_ServerValidate" />

<asp:TextBox ID="txtResourceEndDate" runat="server"
    CssClass="textBox mandatory dateField" />
<asp:CustomValidator ID="valResourceEndDateIsDate" runat="server"
    ControlToValidate="txtResourceEndDate" Display="None"
    ErrorMessage="End date must be a valid date"
    OnServerValidate="Date_ServerValidate" />

<asp:CustomValidator Display="None" Text="" ID="valForStartEndDate" runat="server"
    OnServerValidate="ValidateStartEndDate"
    ErrorMessage="Last day must be greater than or equal to first day" />
protected void Date_ServerValidate(object source, ServerValidateEventArgs args)
{
    DateTime outDate;
    args.IsValid = DateTime.TryParse(args.Value, out outDate);
}

protected void ValidateStartEndDate(object sender, ServerValidateEventArgs e)
{
    e.IsValid = DateTime.Parse(txtResourceEndDate.Text) >=
                DateTime.Parse(txtResourceStartDate.Text);
}

The problem is that the ValidateStartEndDate validator is firing before the Date_ServerValidate validator, so if the date is not valid, a format exception is thrown on DateTime.Parse. Obviously this validator could check for a valid date before parsing, but I’d really prefer to have a discrete validator with an appropriate message.

So the question is this: what determines the sequence with which the validators fire? Unless I’m missing something, this is not declared at the tag level.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:09:03+00:00Added an answer on May 15, 2026 at 10:09 pm

    You can’t count on a certain sequence the validators will fire and also you shouldnt. You have to make sure for yourself that the order is irrelevant.

    So you could

    1. check for the valid date
      simultaneously with the
      Equal-Greater-Check.
    2. First Call your IsDate-Validator’s Validate()-Function and then check if it IsValid
    3. All validators are added to the Page.Validators collection and validation runs through this collection in order. If your logic really should rely on this order: change the order of the validators in the ASPX-Page

    Some interesting infos about Page-Validation: http://msdn.microsoft.com/en-us/library/aa479045.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables on a webform. On a button click I want to
I have two sites one is written in asp.net webforms and the other one
I have a webform, and a custom validation function. Which both work fine. But
I have a webform with a custom calidator function. in the form is a
I have a WebForm that contains the following definition for the FCKeditor: <FCKeditorV2:FCKeditor ID=txtBody
Currently I have a webform that has a series of links. What I'd like
I have a WebForms page that has two DropDownList controls on it that both
I have two logical groups of input fields I need to validate separately using
i have 5 checkboxes in my vb.net webform i want when two checkboxes are
I have two webforms that is used to keep track of confirmations of orders.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.