protected void Login1_LoggedIn(object sender, EventArgs e)
    {
        //MHOCommon.ClearCurrentSession();
        Session.Remove("Error");
        aspnet_Users user = new aspnet_Users();
        user.GetUserByName(Login1.UserName);

        // Validate User IP and Status
        // Check if the logged user is valid under his current IP
        OrgUser objOrgUser = new OrgUser();
        if (!objOrgUser.ValidateUserIPStatus(user.UserId, MHOCommon.CurrentOrgIP))
        {
            if (MHOCommon.EnableSmartLogin == 1)
            {
                FormsAuthentication.SignOut();
                Session["Error"] = true;
            }
        }

        OrgUser orgUser = new OrgUser();
        orgUser.LoadByPrimaryKey(user.UserId);

        if (orgUser.Status)
        {

            if (Roles.IsUserInRole(Login1.UserName, "SuperAdmin"))
            {
                Response.Redirect("~/Admin/AdminHomePage.aspx");
            }
            else if ( Roles.IsUserInRole(Login1.UserName, "SubAdmin"))
            {
                Response.Redirect("~/Admin/SubAdminHome.aspx");
            }
            else if (Roles.IsUserInRole(Login1.UserName, "Admin"))
            {
                Response.Redirect("~/Admin/AdminGovHome.aspx");
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }
        else
        {
            FormsAuthentication.SignOut();
            Session["Error"] = true;

        }
    }
    /// <summary>
    /// Load data
    /// </summary>
    private void LoadData()
    {
        if (UserId != null)
        {
            aspnet_Users aspnet_Users = new aspnet_Users();
            DataTable dt = aspnet_Users.GetUserData(UserId.Value);
            if (dt.Rows.Count > 0)
            {
                dropRole.SelectedIndex = dropRole.Items.IndexOf(
                                           dropRole.Items.FindByValue(dt.Rows[0]["RoleId"].ToString().ToUpper()));

                txtqulification.Text = dt.Rows[0]["QualificationInfo"].ToString();
                txtPhoneNo.Text = dt.Rows[0]["PhoneNumber"].ToString();
                if (dt.Rows[0]["GovId"] != System.DBNull.Value)
                {

                    drpGov.SelectedIndex = drpGov.Items.IndexOf(
                                           drpGov.Items.FindByValue(dt.Rows[0]["GovId"].ToString()));
                    drpGov_SelectedIndexChanged(null, null);
                }
                if (dt.Rows[0]["CivilId"] != System.DBNull.Value)
                {
                    drpCivil.SelectedIndex = drpCivil.Items.IndexOf(
                                           drpCivil.Items.FindByValue(dt.Rows[0]["CivilId"].ToString()));

                    drpCivil_SelectedIndexChanged(null, null);
                }
                if (dt.Rows[0]["HealthOfficeId"] != System.DBNull.Value)
                {
                    drpHealthOffice.SelectedIndex = drpHealthOffice.Items.IndexOf(
                                           drpHealthOffice.Items.FindByValue(dt.Rows[0]["HealthOfficeId"].ToString()));

                }
                txtNationalId.Text = dt.Rows[0]["NationalId"].ToString();
                txtFirstName.Text = dt.Rows[0]["FirstName"] != System.DBNull.Value ? dt.Rows[0]["FirstName"].ToString() : string.Empty;
                txtFatherName.Text = dt.Rows[0]["FatherName"] != System.DBNull.Value ? dt.Rows[0]["FatherName"].ToString() : string.Empty;
                Email.Text = dt.Rows[0]["Email"].ToString();
                drpStatus.SelectedIndex = drpStatus.Items.IndexOf(
                                          drpStatus.Items.FindByValue(dt.Rows[0]["Status"].ToString() == "True" ? "1" : "0"));

                UserName.Text = dt.Rows[0]["UserName"].ToString();
            }
        }
        else
        {
            btnEdit.Enabled = false;
        }
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {
        try
        {

            DropDownList dropOrg = (DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("droOrg");
            DropDownList dropRole = (DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("dropRole");
            TextBox txtPhoneNumber = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtPhoneNo");
            TextBox txtQalification = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtqulification");
            DropDownList dropStatus = (DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("drpStatus");

            OrgUser orgUser = new MHO.BLL.OrgUser();
            aspnet_Users user = new aspnet_Users();
            // string currentUserName = user.UserName;
            user.GetUserByName(((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("username")).Text);
            orgUser.Insert(user.UserId, FirstName.Text, FatherName.Text, NationalId.Text, Convert.ToInt32(DropGov.SelectedValue), Convert.ToInt32(DrpCivil.SelectedValue), Convert.ToInt32(DrpHealthOffice.SelectedValue),
                txtPhoneNumber.Text, txtQalification.Text, dropStatus.SelectedValue == "1" ? true : false);
            Roles.AddUserToRole(((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("username")).Text, dropRole.SelectedValue);
            user = null;
            aspnet_Users user1 = new aspnet_Users();
            user1.GetUserByName(Page.User.Identity.Name);
            // CreateUserWizard1.MoveTo(CreateUserWizardStep2);
        }
        catch (Exception ex)
        {
        }
        finally
        {
            Response.Redirect("RegisterUserResult.aspx");
        }
    }