Hi,
I have a login control. In that Login button is there. my problem is, while clicking on Login button, event is not firing. please see the below code. Please help me..
Login.aspx page code--
<asp:Login ID="Login1" runat="server" OnAuthenticate="Login1_Authenticate" OnLoggedIn="Login1_LoggedIn"
LabelStyle-ForeColor="white" CheckBoxStyle-ForeColor="White"
Height="133px" Width="290px" >
<CheckBoxStyle ForeColor="White"></CheckBoxStyle>
<LoginButtonStyle ></LoginButtonStyle>
<LayoutTemplate>
<table border="0" >
<tr>
<td style="color: white; background-color: transparent;" align="right">
<asp:Label ID="UserNameLabel" Text="User Name :" runat="server" ForeColor="Gray" AssociatedControlID="UserName" Font-Bold="true"></asp:Label>
</td>
<td>
<asp:TextBox ID="UserName" runat="server" Width="120px"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td style="color: white; background-color: transparent;" align="right">
<asp:Label ID="PasswordLabel" runat="server" Text="Password:" ForeColor="Gray" AssociatedControlID="Password" Font-Bold="true"></asp:Label>
</td>
<td>
<asp:TextBox ID="Password" runat="server" TextMode="Password" Width="120px" ></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr runat="server" id="tdDate" >
<td style="color: white; background-color: transparent;" align="right">
<asp:Label ID="lblDate" runat="server" Font-Bold="true">Date:</asp:Label>
</td>
<td>
<asp:TextBox ID="txtSystemDate" runat="server" Height="20px"></asp:TextBox>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="Login1" />
</td>
</tr>
<tr>
<td colspan="2" valign="top" align="center">
<asp:HyperLink Font-Underline="false" ID="hlFPwd" ForeColor="LightBlue" CssClass="text form-control"
Target="_self" NavigateUrl="~/ForgotPassword.aspx" runat="server" Text="Forgot Password ?"
Visible="true" BackColor="Transparent" Font-Bold="true"></asp:HyperLink>
</td>
</tr>
<tr>
<td align="left" colspan="2" style="color: Red;">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
</table>
</LayoutTemplate>
<LabelStyle ForeColor="White"></LabelStyle>
</asp:Login>
Login.aspx.cs page code--
protected void Page_Load(object sender, EventArgs e)
{
TextBox txtSystemDate = (TextBox)Login1.FindControl("txtSystemDate");
Label lblDate = (Label)Login1.FindControl("lblDate");
if (txtSystemDate.Text == "")
{
txtSystemDate.Text = DateTime.Today.ToString("MM/dd/yyyy");
}
if (ConfigurationSettings.AppSettings["SysteminProduction"].ToString() == "Yes")
{
lblDate.Visible = false;
txtSystemDate.Visible = false;
}
KeyValues = (Dictionary<String, String>)Application["KeyValues"];
if (ConfigurationSettings.AppSettings["SharepointLogin"].ToString() == "Yes")
{
string username = Context.User.Identity.Name.Substring(Context.User.Identity.Name.IndexOf('\\') + 1);
if (username != "")
{
AutoLogin(username + "@gh.com");
}
}
Login1.Focus();
}
protected override void OnInit(EventArgs e)
{
if (!IsPostBack && Session["user"] == null)
{
if (Request.Cookies["Cook"] != null)
{
HttpCookie cookie = Request.Cookies["Cook"];
string userId = cookie.Values["userId"].ToString();
string pwd = cookie.Values["pwd"].ToString();
int PrimaryRoleID = 0;
int HRID = 0;
bool _IsActive = false;
int LoginId = APMSUser.ValidateLogin(userId, pwd, out PrimaryRoleID, out HRID, out _IsActive);
if (LoginId > 0)
{
Session["LoginId"] = LoginId;
Session["PrimaryRole"] = PrimaryRoleID;
Session["HRID"] = HRID;
IsEmpActive = _IsActive;
}
if (_IsActive == false)
{
doLogin(userId, pwd);
}
else
{
Login1.FailureText = "You have been deactivated, please contact administrator.";
}
}
}
base.OnInit(e);
}
public void Login1_Authenticate(object sender, System.Web.UI.WebControls.AuthenticateEventArgs e)
{
int LoginId;
int PrimaryRoleID = 0;
int HRID = 0;
bool isMatched = false;
bool beforelogin = true;
bool _IsActive = false;
DataSet dsLogcheck;
PrjMgmtComps.CDataManager.CDataManager objloginCheck = new PrjMgmtComps.CDataManager.CDataManager();
dsLogcheck = objloginCheck.LoginLock(Login1.UserName, isMatched, beforelogin);
if (dsLogcheck.Tables[0].Rows.Count != 0)
{
if (Convert.ToInt32(dsLogcheck.Tables[0].Rows[0]["LoginAttempts"].ToString()) >= 3)
{
LoginId = 0;
}
else
{
LoginId = APMSUser.ValidateLogin(Login1.UserName, Login1.Password, out PrimaryRoleID, out HRID, out _IsActive);
IsEmpActive = _IsActive;
}
}
else
{
LoginId = APMSUser.ValidateLogin(Login1.UserName, Login1.Password, out PrimaryRoleID, out HRID, out _IsActive);
IsEmpActive = _IsActive;
}
if (LoginId > 0)
{
if (IsEmpActive == false)
{
e.Authenticated = true;
isMatched = true;
beforelogin = false;
dsLogcheck = objloginCheck.LoginLock(Login1.UserName, isMatched, beforelogin);
Session["LoginId"] = LoginId;
Session["PrimaryRole"] = PrimaryRoleID;
Session["HRID"] = HRID;
}
else
{
Login1.FailureText = "You have been deactivated, please contact administrator.";
}
}
else
{
int GuestID = APMSUser.GuestLogin(Login1.UserName, Login1.Password);
Session["GuestID"] = GuestID;
isMatched = false;
beforelogin = false;
dsLogcheck = objloginCheck.LoginLock(Login1.UserName, isMatched, beforelogin);
if (dsLogcheck.Tables[0].Rows.Count != 0)
{
if (dsLogcheck.Tables[0].Rows[0]["IsLockedOut"].ToString() == "True")
{
Login1.FailureText = "Your password has been locked please change your Password!!";
Session["PrimaryRole"] = 1323;
}
}
else
{
if (GuestID.Equals(0))
{
Login1.FailureText = "Login Incorrect.Try Again!!";
Session["PrimaryRole"] = 1323;
}
else
{
Response.Redirect(@"apc\Portfolio_Modules.aspx");
}
}
}
}
public void Login1_LoggedIn(object sender, EventArgs e)
{
if (IsEmpActive == false)
{
doLogin(Login1.UserName, Login1.Password);
}
else
{
Login1.FailureText = "You have been deactivated, please contact administrator.";
}
}
public void doLogin(string strUserID, string strPassword)
{
try
{
CController objUser = new CController();
PrjMgmtComps.ObjectFactory.CSecurity obj = new PrjMgmtComps.ObjectFactory.CSecurity();
obj = objUser.Login(strUserID, strPassword);
if (obj.LoginId.ToString() != null)
{
if (obj.LoginId.ToString() != "0")
{
Session["LoginId"] = obj.LoginId.ToString();
Session["LoginName"] = obj.LoginName.ToString();
Session["ModulePermission"] = obj.dtModulePermission;
Session["ChildEntity"] = obj.dtChildEntity;
Session["GroupName"] = obj.GroupName.ToString();
Session["Mail"] = obj.Mail.ToString();
Session["UserID"] = obj.LoginId.ToString();
string RestrictedRole = "";
DataView dv = new DataView(obj.dtModulePermission, "RestrictedRole='Restricted Role'", "RestrictedRole", DataViewRowState.CurrentRows);
if (dv.Count > 0)
{
RestrictedRole = "Yes";
}
else
{
RestrictedRole = "No";
}
Session["RestrictedRole"] = RestrictedRole.ToString();
TextBox txtSystemDate = (TextBox)Login1.FindControl("txtSystemDate");
if (txtSystemDate.Text == "")
{
txtSystemDate.Text = DateTime.Today.ToString("MM/dd/yyyy");
}
Session["SystemDate"] = txtSystemDate.Text;
Session["LoginPage"] = "NO";
if (obj.IsChanged == true)
{
if (ConfigurationManager.AppSettings["SysteminProduction"].ToString() == "No")
{
Response.Redirect(@"Portfolio\ICVMain.aspx");
}
else
{
Response.Redirect(@"Portfolio\PortfoliloMain.aspx");
}
}
else
{
Session["LoginPage"] = "Yes";
Server.Transfer("Portfolio\\APMS\\ChangePassword.aspx");
}
Response.Redirect(@"apc\PortfoliloMain.aspx?m=yes");
}
}
}
catch (Exception ex)
{
throw ex;
}
}
[Edit member="Tadit"]
Added
pre
tags.
[/Edit]