More in this section

Forums / Developing with Sitefinity / How to customize users.aspx

How to customize users.aspx

4 posts, 0 answered
  1. MJia
    MJia avatar
    44 posts
    Registered:
    09 Jun 2009
    29 Jan 2010
    Link to this post
    Our client has the below requirements when creating a new user:
    Instead of typing password, the system generate a temporary password and then email this password to the new user.

    How should I customize the /sitefinity/admin/cmsadmin/user.aspx to meet this requirement?
    It is easy to make the password input textbox hidden, but how to work on the code behind to generate a password before creating the user, and to send email after user created?

    Thanks.
    Michael
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    01 Feb 2010
    Link to this post
    Hi MJia,

    To generate the password you can use Random class

    Random rand = new Random();
    byte[] bytes = new byte[8];
    rand.NextBytes(bytes);
    for (int ctr = 0; ctr <= 4; ctr++)
       Response.Write(rand.Next(101));

    In the code behind of users.aspx you can subscribe for manageUsers.CreatedUser or  manageUsers.CreatingUser event, set the password and send an email to this subscriber.


    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. MJia
    MJia avatar
    44 posts
    Registered:
    09 Jun 2009
    01 Feb 2010
    Link to this post
    Thanks Ivan.
    I can succssefully override the creating user event, but I don't know how to overwrite the password in this event.
    Should I use 'findcontrol' to locate the password textbox and set the value? If yes, please give me an example of using 'findcontrol' to locate the password textbox.  If no, please tell me what to do.

    Thanks.
    Michael
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    02 Feb 2010
    Link to this post
    Hi MJia,

    1. You need to remove the password validator from the template, otherwise you will not be able to click "save" button.

    2. Below is a sample that shows how to get the TextBox for the password

    void manageUsers_CreatingUser(object source, ActionCancelEventArgs e)
        {
             
            TextBox tb = FindControlRecursive(manageUsers, "Password") as TextBox;
     
        }
     
     
        private Control FindControlRecursive(Control root, string id)
        {
            if (root.ID == id)
            {
                return root;
            }
     
            foreach (Control c in root.Controls)
            {
                Control t = FindControlRecursive(c, id);
                if (t != null)
                {
                    return t;
                }
            }
     
            return null;
        }


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
Register for webinar
4 posts, 0 answered