0
votes

I have below code which is working fine. I have to run two different server side function (which can not be run on the same time i have differentiated).

  1. Default.aspx/AddCart
  2. btnUpdate Click Event

My Problem is alert box coming & loading div(#overlay) is hiding before btnUpdate Click Event completion. I dont want to come alert message box & want to show loading div until Click Event not completed.

$("#overlay").show();
$.ajax({
    type: "POST",
    url: "Default.aspx/AddCart",
    data: "{id: " + selectValue + ", qty:" + qq + "}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (r) {
        document.getElementById("<%= btnUpdate.ClientID %>").click();
        alert("Added to Shopping Cart  !");
        $("#overlay").hide();
    },
    error: function (r) {
        alert(r.responseText);
        $("#overlay").hide();
    },
    failure: function (r) {
        alert(r.responseText);
        $("#overlay").hide();
    }
});
1
Why don't you call update click using ajax?Imad
Actually this Click event is Updating UpdatePanel of Header User Control From Default.aspx & i am unable to do this using AJAX/WebMethod.Yusuf
you have to call the click event with ajax too. There is no other way.yogihosting
I think you might wanna make the call to the click function async. Look for documentation for $promise and $.deffered, and then you could hide the #overlay div after that call is completed.Spluf
I know this may not be the perfect solution but you can do one thing add a jquery sleep command for 3 to 4 seconds just before alert("Added to Shopping Cart !"); . So that the button click completes in this time then your alert will call.yogihosting

1 Answers

0
votes

In you button click event, add these line at last.

string script = "alert('Added to Shopping Cart  !'); $('#overlay').hide();"
ScriptManager.RegisterStartupScript(Page, typeof(Page), "sc", script, true);

and remove them from jquery, after click is called.