I have
<asp:Button ID="Submit_BT" runat="server" OnClientClick="return clientClick();" OnClick="Submit_BT_Click" />
And then in JS:
function clientClick(){
// using jQuery
$.get(..., function(result){
// Perform some processing on result
// Proceed with the server-side postback
},
function(error){
// Don't proceed with server-side postback
});
return true; // ?---
}
I want the $.get to successfully complete before postback, but I think postback will never happen, or will always happen. Can I simply say return $.get(...); How to do this?
This question is similar, and the solution is to set async: false, which partially answers my question. When the call completes, it could be either successful or erroneous. Only when the call is successful do I want to proceed with the server-side click. How do I "return true or false" from inside the $.get()'s handlers?
You can always return false in your JS function to assure that it won't postback on click.
And do manual postback in succesful async callback:
$.get(..., function(result){
// Perform some processing on result
__doPostBack('Submit_BT', '')
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With