+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / modifying user.aspx

modifying user.aspx

4 posts, 1 answered
  1. tim
    tim avatar
    27 posts
    Registered:
    12 Oct 2010
    01 Nov 2010
    Link to this post
    hi

    I have made a copy of user.aspx (from the admin) and that all works fine, but I wanted to add a dropdown list ibnto the page with the list items being pulled from a db query, for the life of me I cannot get anything to appear this and the code behind doesnt pick up the fact its in the page at all, I guess Im missing something simple like a reference somewhere but could do with a pointer as its driving me nuts !

    ta
    tim
  2. tim
    tim avatar
    27 posts
    Registered:
    12 Oct 2010
    01 Nov 2010
    Link to this post
    heres the code I have at present, it just doesnt seem to do anything....argh.

    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
     
    using Telerik.Cms;
    using Telerik.Cms.Engine;
    using Telerik.Cms.Security;
    using Telerik.Cms.Web;
    using Telerik.Cms.Web.UI;
    using Telerik.Personalization;
    using Telerik.Web.UI;
    using Telerik.Security;
    using Telerik.Security.WebControls;
     
    public partial class Sitefinity_Admin_CmsAdmin_Users : AdminPage
    {
     
        public override string MenuItemName
        {
            get { return "admin_users"; }
        }
     
        public override int RightsRequired
        {
            get
            {
                return GlobalRights.ManageUsers;
            }
        }
     
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            manageUsers.ModeChanged += new EventHandler(manageUsers_ModeChanged);
            manageUsers.CreatedRole += new RoleCreatedEventHandler(manageUsers_CreatedRole);
        }
     
        void manageUsers_CreatedRole(object sender, GlobalPermissionsEventArgs e)
        {
            if (UserManager.Default.RoleProvider.Name == e.RoleProviderName)
            {
                GlobalPermissions.Instance.SetPermissions(e.GlobalPermissions, 0, UserManager.Default.RoleProvider.Name, new string[] { e.Role });
            }
        }
     
        private void BindForEdit()
        {
     
            DropDownList uxCustomerID = GetCustomerDropDown();
     
            if (uxCustomerID != null)
            {
                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnectStr"].ToString());
     
                uxCustomerID.Items.Clear();
                uxCustomerID.Items.Insert(0, new ListItem("Please select...", ""));
     
                int counter = 1;
     
                SqlCommand cmd = new SqlCommand("GET_LIST", con);
                cmd.CommandType = CommandType.StoredProcedure;
                con.Open();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds, "client_list");
                con.Close();
     
                foreach (DataRow dr in ds.Tables["client_list"].Rows)
                {
                    uxCustomerID.Items.Insert(counter, new ListItem(dr["NAME1"].ToString(), dr["NAME_ID"].ToString()));
                    counter++;
                }
            }
        }
     
        private DropDownList GetCustomerDropDown()
        {
            Control container = manageUsers.GetCurrentContainer();
            DropDownList combo = null;
            if (container is ManageUsers.EditContainer)
            {
                ManageUsers.EditContainer editCont = container as ManageUsers.EditContainer;
                ManageProfile.EditContainer editProfile = editCont.ProfileControl.Controls[0] as ManageProfile.EditContainer;
                if (editProfile != null)
                {
                    combo = editProfile.GetControl<DropDownList>("ddlCompany_Name", false);
                }
                else
                {
                    ManageProfile.InsertContainer insertContainer = editCont.ProfileControl.Controls[0] as ManageProfile.InsertContainer;
                    combo = (insertContainer).GetControl<DropDownList>("ddlCompany_Name", false);
                }
            }
            return combo;
        }
     
        protected void Page_Load(object sender, EventArgs e)
        {
            manageUsers.AttachCommandPanel(usersCommands);
     
            if (!Page.IsPostBack)
            {
                if (Request.QueryString.Get("mode") != null
                    && Request.QueryString.Get("mode").Equals("new"))
                {
                    manageUsers.Mode = ManageUsers.Modes.Insert;
                }
     
                if (Request.QueryString.Get("action") != null &&
                    Request.QueryString.Get("action").Equals("profile") &&
                    Request.QueryString.Get("username") != null)
                {  // access to profile from Newsletter groups (CMS users)
                    string username = Request.QueryString.Get("username");
                    manageUsers.UserName = username;
                }
            }
            if (Membership.Providers.Count <= 1 || Roles.Providers.Count <= 1)
            {
                HtmlControl div = this.usersCommands.Container.FindControl("providersPanel") as HtmlControl;
                if (div != null)
                    div.Visible = false;
            }
        }
     
        void manageUsers_ModeChanged(object sender, EventArgs e)
        {
            switch (manageUsers.Mode)
            {
                case ManageUsers.Modes.List:
                    this.ControlPanelTitle.InnerText = (string)GetLocalResourceObject("Users");
                    break;
                case ManageUsers.Modes.Insert:
                    {
                        this.ControlPanelTitle.InnerText = String.Format("{0} > {1}", (string)GetLocalResourceObject("Users"), (string)GetLocalResourceObject("CreateNew"));
                        SetFaqVisibility();
                        break;
                    }
                case ManageUsers.Modes.Edit:
                    {
                        BindForEdit();
                        this.ControlPanelTitle.InnerText = String.Format("{0} > {1}", (string)GetLocalResourceObject("Users"), (string)GetLocalResourceObject("Edit"));
                        SetFaqVisibility();
                        break;
                    }
                case ManageUsers.Modes.Roles:
                    this.ControlPanelTitle.InnerText = (string)GetLocalResourceObject("Roles");
                    break;
            }
        }
     
        protected void passwordRecoveryButton_Click(object sender, EventArgs e)
        {
            string newPassword = manageUsers.Manager.MembershipProvider.ResetPassword(manageUsers.UserName, "42");
            Telerik.Security.WebControls.ManageUsers.EditContainer editContainer = manageUsers.GetCurrentContainer() as Telerik.Security.WebControls.ManageUsers.EditContainer;
            if (editContainer != null)
            {
                Control passRecovery = editContainer.FindControl("passwordRecoveryButton");
                if (passRecovery != null)
                {
                    int index = editContainer.Controls.IndexOf(passRecovery);
     
                    Literal newPass = new Literal();
                    newPass.Text = "New password: ";
     
                    Label newNote = new Label();
                    newNote.Controls.Add(newPass);
                    Literal passLiteral = new Literal();
                    passLiteral.Text = newPassword;
                    HtmlGenericControl strong = new HtmlGenericControl("strong");
                    strong.Controls.Add(passLiteral);
     
                    newNote.Controls.Add(strong);
     
                    editContainer.Controls.AddAt(index + 1, newNote);
                }
            }
        }
     
        private void SetFaqVisibility()
        {
            Control container = manageUsers.GetCurrentContainer();
     
            if (container == null) return;
     
            HtmlGenericControl divFaq = container.FindControl("divFaq") as HtmlGenericControl;
     
            if (divFaq != null)
            {
                divFaq.Visible = Telerik.Personalization.PersonalizationManager.DefaultInstance.GetGlobalValue<bool>(Telerik.Personalization.GlobalSettingConstants.ShowFaq, true);
     
                if (divFaq.Visible)
                {
                    HtmlAnchor lnkHideFaq = container.FindControl("lnkHideFaq") as HtmlAnchor;
     
                    if (lnkHideFaq != null)
                    {
                        string script = string.Format(System.Globalization.CultureInfo.CurrentCulture, "javascript:Personalization.hideFaqSection('{0}')", divFaq.ClientID);
     
                        lnkHideFaq.Attributes.Add("onclick", script);
                    }
                }
            }
        }
    }

    and then in the aspx page I have

    <asp:DropDownList ID="ddlCompany_Value" runat="server"></asp:DropDownList>

    any thoughts ?

    tim


  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    01 Nov 2010
    Link to this post
    Hi tim,

    This method - GetCustomerDropDown(); is not implemented in your code, so you cannot get a reference to the RadComboBox. You can review the following post again which shows how to reference the control and populate it.

    Your Combobox should be inside ManageProfile.EditContainer and you can get a reference to it from

    sample

    Telerik.Security.WebControls.ManageUsers.EditContainer editContainer = manageUsers.GetCurrentContainer() as Telerik.Security.WebControls.ManageUsers.EditContainer;
    if (editContainer != null)
    {
        ManageProfile p = editContainer.FindControl("manageProfile") as ManageProfile;
        var container = (((System.Web.UI.WebControls.CompositeControl)(p)).Controls[0]);
        if (container is ManageProfile.EditContainer)
        {
            var editCont = container;
            foreach (Control co in editCont.Controls)
                if (co is DropDownList)
                {
                    // do your logic here - retrive the data you need and set selected item of the DropDownList control
                }
        }
        if (container is ManageProfile.InsertContainer)
        {
            var insertCont = container;
            foreach (Control co in insertCont.Controls)
                if (co is DropDownList)
                {
                    // do your logic here - retrive the data you need and set selected item of the DropDownList control
                }
        }
    }


    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  4. tim
    tim avatar
    27 posts
    Registered:
    12 Oct 2010
    02 Nov 2010
    Link to this post
    doh!
    just realised I had this in the more options panel, hence it never finding it, moved it up into user details part and it works fine, so thank you, but.... *if* I wanted to move it into the more options panel, how would I reference it there. It sees the panel but none of the controls in it.

    thanks (again)

    tim
Register for webinar
4 posts, 1 answered