protected void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) { dropRoles.DataSource = Role.GetAllRoles(); dropRoles.DataTextField = "Name"; dropRoles.DataBind(); // Get User Id from query string if (Request.QueryString["id"] != null) { UserId = Int32.Parse(Request.QueryString["id"]); } // Display current user data when user ID is not 0 if (UserId != 0) { ITUser objUser = ITUser.GetUserById(UserId); txtUsername.Text = objUser.Username; dropRoles.SelectedValue = objUser.RoleName; txtEmail.Text = objUser.Email; if (String.Compare(User.Identity.Name, objUser.Username, true) == 0) { IsCurrentUser = true; } } // Hide password textboxes when not forms authentication if (User.Identity.AuthenticationType != "Forms") { formsPassword.Visible = false; } } }
protected void SaveUser(Object s, EventArgs e) { bool isCurrentUser = false; if (Page.IsValid) { ITUser objUser = new ITUser(); if (UserId != 0) { objUser = ITUser.GetUserById(UserId); } objUser.Username = txtUsername.Text; objUser.RoleName = dropRoles.SelectedItem.Text; objUser.Email = txtEmail.Text; if (txtPassword.Text != String.Empty) { objUser.Password = txtPassword.Text; } if (!objUser.Save()) { lblError.Text = "Could not save user"; } else { if (IsCurrentUser) { FormsAuthentication.SignOut(); } Response.Redirect("UserList.aspx"); } } }