Hi,I have following requirement:-
I have a login-popup. When i click on Login Button then it should check if errors in credentials and if errors then it should show error on lebel control of popup otherwise it should redirect to current page(i.e. it should hide the popup after successful login).For my requirement i have done following things
1. I have created a webservice-page(.asmx) with a webMethod and called this method via javascript function.
On doing this my popup div does not hide But I stuck a problem here ,I am unable to show the error message(might be, my code is wrong), every time it shows success message And it does not fire function on success.
kindly guide me where i am wrong while writing the code.
LoginService.asmx
[System.Web.Script.Services.ScriptService]
public class LoginService : System.Web.Services.WebService
{
DataSet ds = new DataSet();
BAL.Service objServiceBal = new BAL.Service();
BAL.Location objLocationBal = new BAL.Location();
BAL.Users objUserBal = new BAL.Users();
Entity.Service objServiceEntity = new Entity.Service();
Entity.Users objUserEntity = new Entity.Users();
string currentPageUrl;
[WebMethod(EnableSession=true)]
public void ValidateUser1(string EmailId, string 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();
}
}
else
{
//loginErrorMessageId.Disabled = false;
//loginErrorMessageId.Visible = true;
//lblLogError.Text = "Invalid UserName or password!";
//loginreg.Visible = true;
////ScriptManager.RegisterStartupScript(this, this.GetType(), "loadLoginRegisterModal", "loadLoginRegisterModal('loginreg');", true);
//Page.ClientScript.RegisterStartupScript(this.GetType(), "loadLoginRegisterModal", "loadLoginRegisterModal('loginreg');", true);
// lbl_InvalidMsg.Text = "Invalid login";
//ScriptManager.RegisterStartupScript(this, this.GetType(), "showModal;", "javascript:showModal('login');", true);
//lblLoginMessage.Text = "You have successfully logged-in.";
}
}
}
javascript function:
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: { EmailId: emailId, password: password },
success: function (data) {
//document.getElementById("dynamicServices").innerHTML = data;
document.getElementById("lblLogError").innerHTML = "You have successfully logged in.";
document.getElementById("lnkLoginHidden").click();
},
error: function () {
document.getElementById("lblLogError").innerHTML = "You have successfully logged in.";
}
});
}
}
aspx page
<div class="form-group">
<label for="login-email" class="col-lg-2 control-label">Email:</label>
<div class="col-lg-10">
<%--<input type="text" name="emailId" id="emailId" class="form-control" placeholder="you@example.com">--%>
<asp:TextBox ID="emailId" runat="server" class="form-control" placeholder="you@example.com" ValidationGroup="LoginGroup_Master"></asp:TextBox>
<asp:RequiredFieldValidator ID="rf_email" runat="server" ControlToValidate="emailId" Text="please enter emailId" SetFocusOnError="true" ForeColor="Red" ValidationGroup="LoginGroup_Master"></asp:RequiredFieldValidator>
</div>
</div>
<div class="form-group">
<label for="login-password" class="col-lg-2 control-label">Password:</label>
<div class="col-lg-10">
<%--<input type="password" name="password" id="password" class="form-control" placeholder="" onkeydown="javascript:fnGetKey(event,'login')">--%>
<asp:TextBox ID="password" runat="server" TextMode="Password" class="form-control" placeholder="" ValidationGroup="LoginGroup_Master" CausesValidation="true"></asp:TextBox>
<asp:RequiredFieldValidator ID="rf_password" runat="server" ControlToValidate="password" Text="please enter password" SetFocusOnError="true" ForeColor="Red" ValidationGroup="LoginGroup_Master"></asp:RequiredFieldValidator>
</div>
<asp:Label ID="lblLogError" runat="server" ForeColor="Red"></asp:Label>
</div>
<%--<div class="alert alert-danger alert-dismissable" style="display: none;" id="loginErrorMessageId" runat="server">Please provide valid email id.</div>--%>
<div class="alert alert-danger alert-dismissable" style="display: none;" id="loginErrorMessageId" runat="server">
</div>
<div class="form-group">
<div class="col-lg-2"></div>
<div class="col-lg-10">
<button type="button" onclick="javascript:login();javascript:loginAjax();">
<strong><strong>Login</strong></strong>
</button>
I am unable to get error message and also on-success linkbutton is unable to hit. Kindly guide me