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

  • Home
  • SEARCH
  • 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 224803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:21:05+00:00 2026-05-11T19:21:05+00:00

I have a form containing a list of input fields that the user populates

  • 0

I have a form containing a list of input fields that the user populates with prices (numbers). I have set their css classes to “required” and “number” so that the jQuery validation plugin validates them accordingly. All that is working perfectly well. The errors are displayed when each field is either not a number or the value is missing etc.

This entire form is actually inside a nyroModal (jQuery plugin) model popup window. But that shouldn’t matter, its just an .aspx web form regardless. Within that, I have also used an UpdatePanel and put everything inside it, because my form is essentially a 2 stage process. There are some basic steps the user must complete on the first ‘page’ of the form. When that validates and works, I just hide/show some elements within the UpdatePanel to show the user the next ‘page’ of the form, which is all the price textbox input fields as described above.

I am using an ImageButton as the trigger point for validating the form. By default, if you just leave an ImageButton the way it is, .Net will fire off a postback, AJAX postback in my case, because its all happening inside an UpdatePanel. Which again, is desired. I don’t want an ugly full postback for obvious reasons.

After lots of reading, I needed a way to attach to .Net’s PageRequestManager in javascript so that I could intercept when .Net wanted to do a postback, based on if jQuery had successfully validated the form or not. So my logic says: By default, do not allow postbacks, but when jQuery successfully validates the form, set a variable which says that postbacks are now allowed, then the next time a postback tries to happen, it will go through. And therefore display success to the user.

This is kind of all working reasonably well, but there is one final problem.

The jQuery validation plugin’s validate({success}) option seems to be wrongly firing after validation is successful on each individual field, not the entire form. I.e. if I enter a number into any one of the price input fields, this success option will fire and set my cancelPostback variable to false, which in turn means that the form now submits even though it hasn’t been validated, just because one field was valid. I would have expected this validate({success}) option to only fire once the entire form was validated.

Have I interpreted this incorrectly, and in fact its doing what its meant to be?
If so, how can I simply set my cancelPostback variable to true ONLY when the ENTIRE FORM is validated?

Thanks heaps for any insight or heads up.

My jQuery code to implement the validation and also intercept the .Net postback event is as follows:

<script type="text/javascript">
    // By default, don't allow Postback until we've successfully validated our form on the client-side.
    var cancelPostback=true;

    // Every single time the page loads, including every single AJAX partial postback
    function pageLoad()
    {
        // Reset the value to say that "We don't allow Postbacks at this stage"..
        cancelPostback=true;

        // Attach client-side validation to the main form
        $("#<%= form1.ClientID %>").validate({ success: function() { alert('validation succeeded!'); cancelPostback = false; } });

        // Grab a reference to the Page Request Manager
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_initializeRequest(onEachRequest);

        alert("Page Load");
    }

    // Our own custom method to be attached to each new/future page request..
    function onEachRequest(sender, args)
    {
        alert("About to cancel? " + cancelPostback);
        // Check to see if we need to Cancel this Postback based on Conditional Logic within this page..
        args.set_cancel(cancelPostback);
    }
</script>
  • 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-11T19:21:05+00:00Added an answer on May 11, 2026 at 7:21 pm

    I would suggest looking at the submitHandler and invalidHandler options. One or the other ought to work for what you want. The best way, I think, would be to allow postbacks by default and set the cancelPostback to true in the invalidHandler. Alternatively, you could write your own submitHandler that calls __doPostBack directly and replaces the submission via the ImageButton.

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

Sidebar

Related Questions

No related questions found

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.