Skip to content Skip to sidebar Skip to footer

Can I Return True To Asp.net Onclientclick After An Ajax Call? Or Maybe Some Other Way?

I m using Ajax call to check whether a user has logged in or not. If not, show login dialog; else I want OnClientClick to return true so that the form will submit. I m thinking abo

Solution 1:

when the condition satisfy, you can submit the form manually on response of ajax call using document.forms['myForm'].submit(). Make the button as normal button(not submit button) and remove the return before the function call in the button element and then do as below:

function buttonSubmitOnclick() {
  showLogin();
  }


//========== 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(); // display the pop up
        }else{
        document.forms['myForm'].submit() // else submit the form,'myForm' is form id'
            }
    }
  }
  xmlhttp.open("GET", "AjaxService.aspx?t=auth", true);  
  xmlhttp.send();
}

Post a Comment for "Can I Return True To Asp.net Onclientclick After An Ajax Call? Or Maybe Some Other Way?"