Edit/Save selected user's Profile ( instead of currently logged in user)

I need a user management page for the administrator whereby the admin can edit/update Profiles from other users(by selecting their username).

How can I select a different users Profile? So far I found only the editing of current user :(

0
wallace740
3/17/2009 4:08:58 PM
asp.net.security 27051 articles. 1 followers. Follow

4 Replies
917 Views

Similar Articles

[PageSpeed] 58

Well you could create your own form and fill it in from the codebehind by following below. Lets say we want to update the firstname and last name in the profile.

Web form 
<table>
  <tr>
    <td>First Name</td>
    <td><asp:TextBox runat="server" ID="firstname" /></td>
  </tr>
  <tr>
    <td>Last Name</td>
    <td><asp:TextBox runat="server" ID="lastname" /></td>
  </tr>
  <tr>
    <td colspan="2"><asp:Button runat="server" id="sumbit_btn" Text="Submit changes" OnClick="submit_btn_click" /></td>
  </tr>
</table>

Code Behind 

protected void Page_Load(object o,EventArgs e)
{
   if(!Page.IsPostBack)
   {
      string user = "someusername";
      ProfileCommon pObj = new ProfileCommon().GetProfile(user);
      if(pObj != null)
      {
          firstname.Text = pObj.FirstName;
          lastname.Text = pObj.LastName;
      }
   }
}

//Button click event
protected void submit_btn_click(object o,EventArgs e)
{
   string user = "someusername";
   //init our Profile Object
   ProfileCommon pObj = new ProfileCommon().GetProfile(user);
   //set the new variables
   pObj.FirstName = firstname.Text;
   pObj.LastName = lastname.Text;
   //save the profile
   pObj.Save();


}
 Good Luck
Please mark post as answer
Obilit.com - Progressive Web Methodologies

My Blog
0
nvanhaaster
3/17/2009 5:26:12 PM

I save/edit the profile but it is not saved :( 

When I go back to select user and come back to edit page, i see that its not saved

I cant find where the problem is Tongue Tied

 

1    using System;
2    using System.Collections;
3    using System.Configuration;
4    using System.Data;
5    using System.Linq;
6    using System.Web;
7    using System.Web.Security;
8    using System.Web.UI;
9    using System.Web.UI.HtmlControls;
10   using System.Web.UI.WebControls;
11   using System.Web.UI.WebControls.WebParts;
12   using System.Xml.Linq;
13   
14   public partial class Administrator_EditUser : System.Web.UI.Page
15   {
16       protected void Page_Load(object sender, EventArgs e)
17       {
18           if (PreviousPage != null)
19           {
20               if (PreviousPage.IsCrossPagePostBack == true)
21               {
22                   Label temp = (Label)PreviousPage.FindControl("selectedUsername");
23                   previous = temp;// = "Cross-page post.";
24                   previousUsername.Text = previous.Text;
25   
26                   if (!Page.IsPostBack)
27                   {
28   
29                       string user = previous.Text;//assign username 
30                       ProfileCommon pObj = new ProfileCommon().GetProfile(user);//select another user
31                       if (pObj != null)
32                       {
33                           //show previously saved profile of selected user
34                           newCompanyName.Text = pObj.CompanyName;
35                           newFirstName.Text = pObj.FirstName;
36                           newLastName.Text = pObj.LastName;
37                           newPrefix.Text = pObj.Prefix;
38                           newInitials.Text = pObj.Initials;
39                           newSex.SelectedValue = pObj.Sex;
40   
41                       }
42                   }
43               }
44           }
45           else
46           {
47               previous.Text = "Not a cross-page post.";
48           }
49   
50       }
51   
52       protected void UpdateButton_Click(object sender, System.EventArgs e)
53       {
54           string user = previous.Text;//assign username
55           ProfileCommon userProfile = Profile.GetProfile(user);
56           userProfile.CompanyName = newCompanyName.Text;
57           userProfile.FirstName = newFirstName.Text;
58           userProfile.LastName = newLastName.Text;
59           userProfile.Prefix = newPrefix.Text;
60           userProfile.Initials = newInitials.Text;
61           userProfile.Sex = newSex.Text;
62           userProfile.Save();
63   
64           Label1.Text = "Profile updated...!<br /><br />";
65           Label1.Text += "Profile read....<br />";
66           Label1.Text += "FirstName: " + userProfile.FirstName;
67           Label1.Text += "&lt;br />LastName: " + userProfile.LastName;
68           Label1.Text += "&lt;br />Initials: " + userProfile.Initials;
69           Label1.Text += "&lt;br />Prefix: " + userProfile.Prefix;
70           Label1.Text += "&lt;br />Sex: " + userProfile.Sex;
71       }
72   
73   
74   }
75   
  
0
wallace740
3/18/2009 9:44:07 AM

 Allright found the mistake

Line 54 -         ProfileCommon userProfile = Profile.GetProfile(previousUsername.Text.ToString());
I was using the temporary value to save the profile,i changed that and now it works

0
wallace740
3/18/2009 10:34:13 AM

Glad to see you got it to work, i was about to start debugging your code, glad i read further down.


Please mark post as answer
Obilit.com - Progressive Web Methodologies

My Blog
0
nvanhaaster
3/18/2009 11:39:31 AM
Reply:

Similar Artilces:

changes made from one user's webpart's page, effects all user's
 I am just doing this offline right now in Visual Web Developer Express 2008I created the login inonce in the memberpage area, people can modify their webpart page. I created several users to test this out.  I loaded it in a browser.When I make changes as logged in user "A" .  Then logout and login as user "B", user "B,s" webpart page has been changed to user "A".This goes true for whomever I log in as.  It changes for everyone.Is there something specific I need to do in order to get everyone's changes to be unique for them...

Unable to access user control's user control's function\property from another user control
Hi, I used to call an user control's user control function as stated below from my user control in ASP.Net 1.1 wucCompany.wucEmployee.GetEmployeeSomething() After migrating to ASP.Net 2.0, I am unable to use any properties/functions(even the public ones) of the user control's User control's from another user control.  The way I have to do is create property\function in wucCompany which calls the wucEmployee's property\function and call the wucDepartment.GetEmployeeSomething().Since I need to do this change in too many places, I can...

Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection
This is my first time to deploy an asp.net2 web site. Everything is working fine on my local computer but when i published the web site on a remote computer i get the error "Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed" (only in pages that try to access the database) Help pleaseee Hi You could take a look at this : http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=152338&SiteID=1Sincerely,Young Fang Hi ...

how do I reteive the profile of a specific user that is not the current logged in user?
I am trying to retreive the profile for a specific user without that user being the current logged in user. I am in a class module and I have tried that but did not work:Dim UserGenProfile As ProfileInfo Dim reccount As IntegerUserGenProfile = ProfileManager.FindProfilesByUserName(ProfileAuthenticationOption.Authenticated, UserName, 0, 1, reccount).Item(0)   Hi Try to implemnt this piece of code ProfileCommon profile = Profile.GetProfile("MyUserName"); string name = profile.Name;Avantha SiriwardanaBeware of bugs in the above code; I have only proved it correct, not...

Unable to cast object of type 'WIM2008_Web.App_Code.wim.security.data.User' to type 'WIM2008_Web.App_Code.wim.security.data.User'
I don't know if i post this in the rigth forum but it is related to database call. this is my code: public DataSet CustomerDetails_Select(Int32 ID)    {      DataSet ds = new DataSet();      WIMConnect wimcon = new WIMConnect();      WIMConnection cnnwim = new WIMConnection();      ConvertDataReaderToDataTable DrToDs = new ConvertDataReaderToDataTable();      GridViewHeadersDao gvh = new GridViewHeadersDao();       &nb...

login failed because user's IsApproved is false for user's account
Hi How can i detect if a user's login fails because their account is not approved yet (i.e IsApproved = false in Membership table) I am using a templated login control and if the user's login fails for this reason all that happens is that the FailureText control is displayed. How can i change the failure text if the user's account is not approved? thanks andrea Use Membership.GetUser Function this function Return a hydrated MembershipUser Object you can access its properties and check the validity see the link below http://msdn2.microsoft.com/en-us/library/40w5063z.aspxRega...

how to change a user's mailbox but keep the user's GW id
We have a user whose email has a space between her first name and middle name, which cause the problem in sending out email or receive email from the outside the network. Can someone advise how and where I suppose to change her email name to a valid name like firstname.middlename.lastname@xxx.com from firstname middle.lastname@xxx.com? Thank you very much! On Tue, 23 Oct 2007 15:27:51 +0000, April wrote: Duplicate. -- Joe Marton Novell Support Forum SysOp Novell does not officially monitor these forums! Use the Internet override - in ConsoleOne, GroupWise Tab, Inte...

Editing and saving profile values of user not logged in
I am building an admin page that I intend to use to editt the Profile values of the users of my application. I am having trouble saving the changes I make to Profile values for users other than me. Here is the approach I am trying. "Name" is a profile property I want to set to a new value. Dim UserProfile As HttpProfile = Profile.GetProfile(UserWhoseProfileIWantToEdit) UserProfile.Name = "New Value" UserProfile.Save() The changes I make to users other than me do not get saved to the database. Could someone please point me in the right direction? Tha...

How to save a dataset to each user's Profile??
I need to store a rather large amount of data for each user of my site. I would like to use a custom dataset to store the data, though there may be a better way of which I am unaware. How do I store a dataset on each user's profile?? Is there a better way??Thanks, Tony A dataset can be very heavy - why and what for are you using the dataset?Sonu Kapoor [MVP] Feel free to ask me any .NET question | Ajax Data Controls Forum basically I'm trying to write a PIM style web app, nothing special, just doing this as practice. so I need a way to store each user's todo items, calendar events, etc. ...

MOD: Edit User's Profile
This MOD replaces the EDIT USERS PROFILE prior functionality and serves two purposes: 1. To separate the actual Registration Page from the Edit User page so that end users may not change their username. Prior to the modifications, the USERS_EDITPROFILE page would inherit the RegisterForm controls which allowed editing and changing of the UserName. 2. Physically separates the EDIT and REGISTER functions such that you may embed additional controls in one or the either and not effect the other. Example: You want to add a “Register for Sub-Forum” control but not have it appear during ...

Logged in User's Profile Image
Hi,Am Trying to display Every Logged in user with a image, similar to - Avatar as in asp.net forum, using httphandler, other then Membership db, have a custom db for User Profile with Image as a field,am able to store the image into the db, but not able display it back on logged in user's profile page, all members are listed using grid view, and their details of profile in form view,i have used HTML Input control                 HTML Image control                ...

Dynamically load the dll's on user's selection
Hi ,  I am in a need to load the dll's dynamically ,based on user's selection and get them added to the References of Solution Explorer in the application(VS 2008,c#) .How can I proceed with this requirement? Any pointers to this would be of great  help. Thanks in advance.   You can use System.Reflection.Assembly.Load().Hope it helps. Jef Claes~~~~~~~~~~Visit my blog Pratibha_Pillai:Hi ,  I am in a need to load the dll's dynamically ,based on user's selection and get them added to the References of Solution Explorer in the application(...

Notes Driver: veto when user's fullname is the same as existing user's fullname
In the Notes Driver, I want to put the policy to veto when the current user's fullname is the same as existing user fullname is Lotus Domino Directory and and in eDirectory. How can I do the query to findout whether the user's fullname is the same as the existing ones or not. Please help.. Thanks Pattarawan. -- pattarawan pattarawan, It appears that in the past few days you have not received a response to your posting. That concerns us, and has triggered this automated reply. Has your problem been resolved? If not, you might try one of the following op...

Save selected records to a table that can be used to display filtered data based on the user's selection in a drop-down list.
When the file name is selected from the drop down list the record IDs from a table field name will be the criteria for WHERE = on the details page that will be used to show related record in a second page.   So right now I can get the selected record ids from the first page.  I am trying to figure out if I can add an option to the Master page where I can get previous selected record ids from a table. Problem:I sometimes select 10   25 records, sometimes the same records each time I access the DB.  Is there a way to save the selections I made as a file name so t...

Web resources about - Edit/Save selected user's Profile ( instead of currently logged in user) - asp.net.security

Resources last updated: 11/23/2015 3:46:37 PM