locked
JavaScript Completion BEFORE Postback RRS feed

Answers

  • User753101303 posted

    Hi,

    I would try to turn my Ajax call into a synchronous call (by using async:false if using jQuery).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 14, 2016 8:11 AM

All replies

  • User475983607 posted

    This seemed like a good approach, but I'm trying to avoid using an html button on my form.

    Keep in mind that an ASP Button simply renders are an HTML submit.  Therefore, you'll end up canceling the default submit behavior anyway.  Why do you feel you need an alternate approach? Did you try to the posted solution?

    Tuesday, December 13, 2016 10:26 PM
  • User-707554951 posted

    Hi jeff.hooper,

    For your problem, add return inside OnClientClick after a function is called. Otherwise, the button will post back even if function returns false.

    <asp:button ID="Button1" runat="server" OnClick="Button1_Click" 
        OnClientClick="return checkValidation()" Text="Submit" />
    
    <script type="text/javascript">
        function checkValidation() {
            return confirm('Everything ok?');
        }
    </script>

    Best regards

    Cathy

    Wednesday, December 14, 2016 7:27 AM
  • User753101303 posted

    Hi,

    I would try to turn my Ajax call into a synchronous call (by using async:false if using jQuery).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 14, 2016 8:11 AM
  • User-366038927 posted

    Keep in mind that an ASP Button simply renders are an HTML submit.  Therefore, you'll end up canceling the default submit behavior anyway.  Why do you feel you need an alternate approach? Did you try to the posted solution?

    I read the posted solution, but I didn't try it.  I was concerned, perhaps unnecessarily so, that I would not be able to put all of my organization's standard ASP button formatting (class="[...]") on the HTML button.  If I'm incorrect about that, then I do need to consider the posted solution.

    Wednesday, December 14, 2016 2:02 PM
  • User-366038927 posted

    I would try to turn my Ajax call into a synchronous call (by using async:false if using jQuery).

    I'm still wrestling with the initial issue that I posted about, but the available contributions will help get me there and the async: false has been very useful in making sure that the jquery is done before the postback.

    Thanks for contributions.

    Thursday, December 15, 2016 1:39 PM