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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:48:19+00:00 2026-05-26T04:48:19+00:00

I need some help with jQuery and stopping an asp.net button postback. If you

  • 0

I need some help with jQuery and stopping an asp.net button postback. If you look at the code below, I defined a variable named err and gave it a value of 0. Then I have jquery get a string from a web service, it’s actually an error string. If the length of this string is 0, then set err equals to 1, otherwise set err equals to 2 because we’re getting back a business rule error.

When I debug the app, it seems that err equals 0, and never 1 or 2. It also seems that the web service gets its value after my last if statement where i’m supposed to stop the postback.

Any help would be appreciated. Thanks.

   $(document).ready(function () {
      $('#<%=Button1.ClientID %>').click(function (e) {

        //Find out the hour and time of the current request
        var myString = $('#<%=DropDownList1.ClientID %>').val();
        var myResult = myString.split(":");
        var myHour = myResult[0];
        var myTime = myResult[1];
        var xDate = $("*[id$='hiddenDate']").val();
        var err = 0;
        //Check to see if the end time of the event somehow falls during a time when another event is occuring.
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "StudiesWebService.asmx/CheckEndTime",
            data: "{'UserName':'" + "jacksonm" + "','xDate':'" + xDate + "','xHour':'" + myHour + "','xMinutes':'" + myTime + "'}",
            dataType: "json",
            success: function (data) {
                var myReturnedString = data.d;
                //if the returned string length is greater than 0, then set err = 2
                if (myReturnedString.length = 0) {
                    err = 1;
                }
                else {
                    err = 2; 

                }

                $('.result').html(myReturnedString);
            },
            error: function (e) {
                $('.result').html("An Error occured checking the validity of this event." + e);
                err = 2;

            }



        });

         //stop the postback here depending on what err equals. 
        if (err == 2) {
            return false;
        }

        else {
            return true;

        }



    });

   });

<asp:Button ID="Button1" runat="server" Text="Submit Time" class="CLOSE" onclick="Button1_Click"   />
  • 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-26T04:48:20+00:00Added an answer on May 26, 2026 at 4:48 am

    Unless your Ajax web service call is actually synchronous then the order your code is executing is not as you expect. Add an alert to your success callback, your error callback, and right before this comment //stop the postback here depending on what err equals. The last alert should happen first, since the web service call won’t return and be executed until after the current function completes.

    In your Ajax call, add this option async: false:

    $.ajax({
            type: "POST",
            async: false,
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to developing JQuery code and i need some help shortening the following:
I have one jQuery code and need some help from u guys to improve
I need some help understanding how jQuery stores elements. Please have a look at
Need some help with a #jQuery issue. Can someone look at this and tell
I need some help getting the jquery cycle plugin to work as below: Basically,
I need some help with jQuery script again :-) Just trying to play with
I'm working with jQuery for the first time and need some help. I have
I need some help adjusting the logic of my jquery function. Here's how the
I am new to jQuery and need some help with the following problem. I
I am very new to jquery and need some help. I am trying to

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.