Click here to Skip to main content
15,892,199 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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--
XML
<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>
                    &nbsp;&nbsp;&nbsp;<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>
                    &nbsp;&nbsp;&nbsp;<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">
                    &nbsp;&nbsp;&nbsp;<asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="Login1" />&nbsp;&nbsp;
                </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>&nbsp;
                </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--
C#
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");//System.DateTime.Now.ToString();
    }
    if (ConfigurationSettings.AppSettings["SysteminProduction"].ToString() == "Yes")
    {
    lblDate.Visible = false;
    txtSystemDate.Visible = false;
    }
    
    //TrailVersion();
    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();
    //Login1_Authenticate();
}

protected override void OnInit(EventArgs e)
{
    //lblYear.Text = DateTime.Now.Date.ToString("yy");
    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)
            {
                // e.Authenticated = true;

                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;

            //Session["SystemDate"] =  // txtSystemDate.Text;
        }
        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;//later get from web.config

            }
        }

        else
        {
            if (GuestID.Equals(0))
            {
                Login1.FailureText = "Login Incorrect.Try Again!!";
                Session["PrimaryRole"] = 1323;//later get from web.config

            }

            else
            {
                Response.Redirect(@"apc\Portfolio_Modules.aspx");
            }
        }
    }

}
public void Login1_LoggedIn(object sender, EventArgs e)
{

    //CheckBox cek = (CheckBox)Login1.FindControl("RememberMe");
    //if (cek != null && cek.Checked)
    //{

    //    HttpCookie cookie = new HttpCookie("Cook");
    //    cookie.Values.Add("userId", Login1.UserName);
    //    cookie.Values.Add("pwd", Login1.Password);
    //    cookie.Expires = DateTime.Now.AddYears(1);
    //    Response.Cookies.Add(cookie);

    //}

    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();
                //Added by Madhu on 14-DEc-2011 to get all in active projects
                //CheckBox chkInActive = (CheckBox)Login1.FindControl("chkInActive");
                //if (chkInActive.Checked)
                //{
                //    Session["ShowAll"] = "True";
                //}
                //else
                //{
                //    Session["ShowAll"] = "False";
                //}


                TextBox txtSystemDate = (TextBox)Login1.FindControl("txtSystemDate");
                if (txtSystemDate.Text == "")
                {
                    txtSystemDate.Text = DateTime.Today.ToString("MM/dd/yyyy");//System.DateTime.Now.ToString();
                }
                Session["SystemDate"] = txtSystemDate.Text;
                //End By Jyoshna

                //if (ChkProfile.Checked == true)
                //  Session["CheckProfile"] = "PROFILE_ON";
                //else
                //  Session["CheckProfile"] = "PROFILE_OFF";
                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");

            }

        }//if
    }
    catch (Exception ex)
    {
        throw ex;
    }
}



[Edit member="Tadit"]
Added pre tags.
[/Edit]
Posted
v3
Comments
Ajesh1986 26-May-14 7:57am    
You Said Your Problem is the login button event not firing.....I am not seeing any button click event on these uploaded codes.... and on your Page Load event try to wrap those codes inside if(!IsPostback){//put ur codes here}....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900