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 8920869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:23:14+00:00 2026-06-15T06:23:14+00:00

I am building a CustomValidator to handle my own application’s logic on time fields

  • 0

I am building a CustomValidator to handle my own application’s logic on time fields (“09:00”, “15:35”, …) but I am stumbling on a behaviour that I haven’t found any explanation for online.

My focus right now is the validation logic that gets executed client-side.

The problem is, as said in the title, that, if and only if I set the ControlToValidate property in the Validator with the ID of the textbox I am validating, the validation gets fired as soon as focus leaves the textbox; it even fires before the onblur event, which is absolutely detrimental for me, since I am using the onblur event to standardize the time formats (eg “9:00” -> “09:00”, “11.45” -> “11:45”) and thus, the validation logic potentially receives an incorrect value. If, on the other hand, the ControlToValidate property remains blank, the ClientValidationFunction is fired only on a submit/postback.

The only related answer I’ve found is this https://stackoverflow.com/a/8649697/450684, but still, to me it makes no sense at all. Why should the presence of a ControlToValidate indicate that I want client-side validation to execute before onblur? I don’t want it! Is there any way to supress this behaviour?

Here is an example page:

<asp:TextBox runat="server" AutoPostBack="false" ID="txtBox1" onblur="FormatText(this);" />
<asp:CustomValidator runat="server" ID="CV1" ControlToValidate="txtBox1" ClientValidationFunction="Test1" />
<asp:CustomValidator runat="server" ID="CV2" ClientValidationFunction="Test2" />
<asp:Button ID="btn1" Text="postback" runat="server" OnClick="btn1_Click" />
<asp:Label ID="lbl1" runat="server" />
<script type="text/javascript">
    function FormatText(txtBox1)
    {
        alert('FormatText');
    }
    function Test1(val, args)
    {
        alert('Test1');

    }
    function Test2(val, args)
    {
        alert('Test2');
    }</script>

What I want is both Test1 and Test2 to execute only on btn1’s click; instead on txtBox1’s onblur event I get Test1 and FormatText executing in this order

ASP.NET’s client validation was really fun for me to write and study, don’t let this ruin everything 🙂

Thx

PS: .NET framework’s version is 4.0. Plus, the server-side language is C#, if it matters

  • 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-06-15T06:23:15+00:00Added an answer on June 15, 2026 at 6:23 am

    I think what is going on is this:

    The standard behavior for ASP.NET client-side validation is to validate when the field is exited. That’s an observation, not a reference to a published standard (although there may be one.) The out-of-the-box validators all behave this way. All of them require specifying a particular field to validate.

    The custom validator allows you to validate a single control (by specifying it with ControlToValidate), or lets you validate a combination of controls, in which case you set ControlToValidate to an empty string. Unless things have changed, you do have to specify it; if you omit the attribute, no validation will occur.

    So … if you specify a control to validate, the custom validator behaves like every other validator and reacts to the user exiting the field. If you don’t specify a control to validate, it doesn’t know what controls you’re interested in, and doesn’t do that.

    You may be able to work around this by writing a truly custom validator: inherit from BaseValidator. That can actually be a lot of fun.

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

Sidebar

Related Questions

Building a multilingual application that should work with the most prevalent global alphabets but
Building an iPhone OS application that will allow users to anonymously post information to
I´m building a small application with Jquery and PHP. Jquery (index.html) adds Form Fields
Building a rails B2B application that will have various users. I'm pretty clear on
Building a kiosk application that only requires button press and button drag(scroller) detection. I
Building a stand alone WPF application that uses a MSSQL backend. I would like
Building on this question: Django Celery Time Limit Exceeded? I have some tasks that
Building a quick view that will display a list of all days but only
Building a Silverlight 5 app that runs in the browser but getting some nagging
Building an excel spreadsheet is a classic asp application. The problem now is that

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.