I am currently implementing an Ajax call to verify if a user is logged in. If the user is not logged in, I want to display a login dialog; otherwise, I need OnClientClick to return true so that the form can be submitted. I am considering using a global variable and checking it until the Ajax call returns a value... I'm unsure if this approach is correct? Thank you!
(the server-side code is already functional)
in .ascx:
<asp:Button ID="buttonSubmit" Text="Submit" OnClientClick="return buttonSubmitOnclick()" OnClick="buttonSubmit_Click" runat="server"/>
in .js:
function buttonSubmitOnclick() {
showLogin();
//What should be done here??? How can I get the result after the ajax call?
}
//========== Ajax ==============
function showLogin() {
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
if (xmlhttp.responseText == "false") {
$find('modalPopupLogin').show(); //Show Login Dialog
};//else is it possible to return a true to buttonSubmitOnclick?
}
}
xmlhttp.open("GET", "AjaxService.aspx?t=auth", true);
xmlhttp.send();
}