public void btnChangepwd_Click(object sender, RoutedEventArgs e) { var obj = ((FrameworkElement)sender).DataContext as Users; string newPass = StringExtensions.GetRandomString(); BL_Users.Update(obj, newPass); BL_Users.SendCredentials(obj.Firstname, obj.Lastname, obj.Email, obj.Username, newPass); MessageBox.Show("The new password has been sent to the user.", "New password"); BindData(); }