2

I have the below JS/Jquery function called in the onclientclick of ASP.NET button which should return true or false or show confirm dialog, the problem is when the $.get function is called it also calls the server side onclick event of the button.. any ideas?

function CheckPaymentStatus()
{
     if(document.getElementById('<%= radio15E.ClientID %>').checked
        {
            $.get("../AJ.ashx?name=John&location=Boston",null).done(
            function(msg)
            {
            return(window.confirm("do you wish to proceed?"));
            })
        }
        else
        {
            return true;
        }   
}
Ayman
  • 21
  • 2
  • Your issue is with scope, your `return confirm` statement is actually returning from the callback function, **not** the `CheckPaymentStatus` function. – Mathew Thompson Apr 28 '15 at 09:40
  • I think you'll have to change your logic, the call to get is asynchronous so the onclientclick returns before the callback from get... – stambikk Apr 28 '15 at 09:41
  • mattytommo please explain more, what i need to do is show the confirm if the ajax query returned true else will return true to proceed with the server side onclick – Ayman Apr 28 '15 at 09:48
  • stambikk any recommendation? – Ayman Apr 28 '15 at 09:48

1 Answers1

0

Is the button you have wired this event up to posting the form? Check the button type; is it a "submit"? Don't use an asp:button, use a simple html button element if you don't want any server side events firing.

garryp
  • 5,508
  • 1
  • 29
  • 41
  • actually it is ASP button & I need it to run server side onclick event in some cases based on the return of the JS – Ayman Apr 28 '15 at 09:45
  • The problem is that because the AJAX call is asynchronous the function returns and doesn't wait on $get. – garryp Apr 28 '15 at 10:57