jQuery Submit and the Heisenberg Effect
<p>I am trying to do a form.submit that will call a non-static event on the server side and force a full postback; however, I am encountering an example of the Heisenberg Effect. If I put a breakpoint on line 3 of code below, the code-behind gets the message and the submit works. If I put the breakpoint on line 4 instead, the submit fails. The server code actually gets the event, but the client doesn't seem to want to wait for the server to do its thing. The correct function should be that line 4 should never be executed.</p>

<pre><code>1) function LoginSubmit() {
2)    $("#diagnostics").text("LoginSubmit started");
3)    $("#&lt;%=btnLoginSubmit.ClientID %&gt;").click();
4)    $("#diagnostics").text("LoginSubmit failed");
5)    }
</code></pre>

<p>Is there a way for me to wait for the server to get and process the btnLoginSubmit event message?</p>

<p>The code below is called when the user clicks the Logout button on the screen. </p>

<pre><code>   function Logout() {
        $("#loginStatus").text("Logged out");
        $("SPAN[id*='lblLoginStatus']").text("");
        $("SPAN[id*='lblLoggedInUserName']").text("");
        $("#userId").text("");
        $("#menuId").text("");
        $("SPAN[id*='spanBtnLogout']").hide();
        $("SPAN[id*='spanBtnLogin']").css("display:inline;");
        $("SPAN[id*='spanBtnLogin']").show();
        $.ajax({
            type: "POST",
            url: "LoginService.asmx/Logout",
            contentType: "application/json; charset=utf-8",
            data: "{}",
            success: function (data, status) {
                $.cookie("LoggedInUserId", null);
                $.cookie("LoggedInMenuId", null);
                $.cookie("LoggedInUserName", null);

                LoginSubmit();  // Force a postback
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("Logout function failed: " + XMLHttpRequest.responseText);
            }
        });
    }
</code></pre>
