Hi Richa, Kindly use WebService to call your procedure.
Here is the sample code
function loginAjax() {
var emailId = document.getElementById("emailId").value;
var password = document.getElementById("password").value;
if (emailId != "" && password != "") {
$.ajax({
url: 'LoginService.asmx/ValidateUser1',
type: 'POST',
data: JSON.stringify({ EmailId: emailId, password: password }),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
if (data.d == "EmptyFields") {
document.getElementById("loginErrorMessageId").style.display = "block";
document.getElementById("loginErrorMessageId").innerHTML = "Please fill both fields.";
}
if (data.d == "1") {
document.getElementById('savebtn').click();
}
else if (data.d == "0") {
document.getElementById("loginErrorMessageId").style.display = "block";
document.getElementById("loginErrorMessageId").innerHTML = "Invalid username/password.";
document.getElementById("showLoginProgressId").style.display = "none";
}
else {
document.getElementById("loginErrorMessageId").style.display = "block";
document.getElementById("loginErrorMessageId").innerHTML = "Invalid username/password.";
document.getElementById("showLoginProgressId").style.display = "none";
// login();
}
},
error: function (data) {
debugger
console.log(data);
document.getElementById("loginErrorMessageId").style.display = "block";
document.getElementById("loginErrorMessageId").innerHTML = "InvaLid username/password.";
document.getElementById("showLoginProgressId").style.display = "none";
//login();
}
});
}
}
LoginService.asmx.cs
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string ValidateUser1(string EmailId, string password)
{
if (EmailId != "" && password != "")
{
if (objUserBal.ValidateUserId(EmailId, password))
{
DataSet ds = new DataSet();
ds = objUserBal.GetUserLoginData(EmailId, password);
if (ds.Tables[0].Rows.Count == 1)
{
HttpContext.Current.Session["EmpName"] = ds.Tables[0].Rows[0]["EMPNAME"].ToString();
HttpContext.Current.Session["SignedIn"] = "1";
HttpContext.Current.Session["UserImage"] = ds.Tables[0].Rows[0]["ImageUrl"].ToString();
HttpContext.Current.Session["UserId"] = ds.Tables[0].Rows[0]["ID"].ToString();
HttpContext.Current.Session["UserType"] = ds.Tables[0].Rows[0]["UserType"].ToString();
HttpContext.Current.Session["GroupID"] = ds.Tables[0].Rows[0]["GroupId"].ToString();
HttpContext.Current.Session["Status"] = ds.Tables[0].Rows[0]["Status"].ToString();
HttpContext.Current.Session["Mobile"] = ds.Tables[0].Rows[0]["MobileNo"].ToString();
HttpContext.Current.Session["Email"] = ds.Tables[0].Rows[0]["Email"].ToString();
}
result = "1";
}
else
{
result = "0";
}
}
else
{
result = "EmptyFields";
}
return result;
}
Here in WebService method you can change code as per your requirement.
And for calling in Button you need to write
<button type="submit" onclick="javascript:loginAjax();"/>
I hope this will help you .