If you see the code for the Edit User Dialogue from the User Manager, here is the location of the file in the Sitecore webroot.
inetpub\wwwroot\<your application root>\sitecore\shell\Applications\Security\EditUser\EditUser.xaml.xml
This file refers to the DLL i.e. Sitecore.Client
and the event is written in this class Sitecore.Shell.Applications.Security.EditUser.EditUserPage
. And here is the code snippet to add Edit User or Role.
protected override void OK_Click()
{
if (!this.Validate() || !this.ValidateTicket())
return;
User user = EditUserPage.GetUser();
Assert.IsNotNull((object) user, typeof (User), "User not found");
UserProfile profile = user.Profile;
Assert.IsNotNull((object) profile, typeof (UserProfile));
try
{
IEnumerable<Role> roles = this.Roles.Items.Cast<System.Web.UI.WebControls.ListItem>().Where<System.Web.UI.WebControls.ListItem>((Func<System.Web.UI.WebControls.ListItem, bool>) (item => System.Web.Security.Roles.RoleExists(item.Value))).Select<System.Web.UI.WebControls.ListItem, Role>((Func<System.Web.UI.WebControls.ListItem, Role>) (item => Role.FromName(item.Value)));
HttpContext current = HttpContext.Current;
Assert.IsNotNull((object) current, typeof (HttpContext));
string controlValue = string.Empty;
foreach (string key in current.Request.Form.Keys)
{
if (key != null && key.EndsWith("StartUrlSelector", StringComparison.InvariantCulture))
{
controlValue = current.Request.Form[key];
break;
}
}
if (controlValue == "Default")
controlValue = string.Empty;
if (controlValue == "Custom")
controlValue = this.StartUrl.Text;
user.Roles.Replace(roles);
....
....
}
So you can override this class and replace it in the XML file to use your logic.
I hope this will help.