$(document).ready(function () { ClearData(); $("#btnLogin").click(function () { Login(); return false; }); $("#btnLogin").keydown(function (e) { if (e.which == 13) { Login(); return false; } }); $("#txtPassword").keydown(function (e) { if (e.which == 13) { Login(); return false; } }); $("#btnForgotten").click(function () { window.location.replace(CommonURL + 'UserLogin/ForgotPassword?User=' + $("#txtUserCode").val() + ''); }); }); function Login() { try { if ($("#txtUserCode").val() == "") { alert("Please enter User Code.!"); $("#txtUserCode").focus(); } else if ($("#txtPassword").val() == "") { alert("Please enter PASSWORD.!"); $("#txtPassword").focus(); } else { EncryptText("txtPassword", "8541254585698541"); BlockUI(); $.post(CommonURL + "UserLogin/Login", AddAntiForgeryToken({ UserCode: $("#txtUserCode").val(), Password: $("#txtPassword").val() }), function (data) { if (data.Result === undefined) { alert(AjaxError(0, 0)); } else if (data.Result != "") { $("#txtPassword").val(""); alert(data.Result); } else if (data.Password == "123") { $(window.location).attr("href", CommonURL + "User/ChangePassword"); } else if (data.Password != "") { $(window.location).attr("href", CommonURL + "Dashboard/Index"); } if (data.Focus != "") { $("#" + data.Focus).focus(); } UnBlockUI(); }).fail(function (xhr, err) { var responseTitle = $(xhr.responseText).filter('title').get(0); alert($(responseTitle).text() + "\n" + AjaxError(xhr, err)); UnBlockUI(); }); } } catch (e) { alert("Error In Login: " + e.message); UnBlockUI(); } } function ClearData() { $("#txtUserCode").val(""); $("#txtPassword").val(""); $("#txtUserCode").focus(); }