Solved

Can't Update Members database Membership.UpdateUser

Posted on 2008-06-16
4
1,174 Views
Last Modified: 2010-04-21
Hi

I have been having a problem updating the ASPNETDB.MDF Created by Visual Studio when creating Membership forms like login new user etc

I Have created a GridView to edit existing user in this database updating Roles works but when i try to Update fields like Email or ISApproved it is not save the changes to the database

    protected void gdvEdit_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int intIndex = Convert.ToInt32(e.RowIndex);
     

        TextBox txtUserName = (TextBox)gdvEdit.Rows[intIndex].FindControl("txtUserName");
        TextBox txtEmail = (TextBox)gdvEdit.Rows[intIndex].FindControl("txtEmail");
        CheckBox chkEditIsLockedOut = (CheckBox)gdvEdit.Rows[intIndex].FindControl("chkEditIsLockedOut");
        ListBox lsbRoles = (ListBox)gdvEdit.Rows[intIndex].FindControl("lsbRoles");

        //Remove all Roles From User
        string[] userRoles = Roles.GetRolesForUser(gdvEdit.DataKeys[intIndex][0].ToString());
        foreach (string strRole in userRoles)
        {
            Roles.RemoveUserFromRole(gdvEdit.DataKeys[intIndex][0].ToString(), strRole);
        }

        //Replace with new selection of roles
        for (int i = 0; i < lsbRoles.Items.Count; i++)
        {
            if (lsbRoles.Items[i].Selected == true)

                Roles.AddUserToRole(gdvEdit.DataKeys[intIndex][0].ToString(), lsbRoles.Items[i].Value);
        }

        string UserName = gdvEdit.DataKeys[intIndex][0].ToString();
        MembershipUser UserDetails = Membership.GetUser(UserName);

        //Update User Details
        UserDetails.IsApproved = true;
        UserDetails.Email = txtEmail.Text.Trim();

        if (chkEditIsLockedOut.Checked == false) { UserDetails.UnlockUser(); }
        Membership.UpdateUser(UserDetails);

        //Rebind GridView
        gdvEdit.EditIndex = -1;
        Bind_gdvEdit();
    }

Any Ideas on why this maybe happing would be appreciated

Thanks
John
0
Comment
Question by:Filtered
  • 2
4 Comments
 

Author Comment

by:Filtered
ID: 21818279
Hi

If anyone would like me to send them the project (it is quite small only has few pages and the database) so that they could step through the code and detect something that i'm unaware of i will gladly send it to them by email as I can not  upload the project to this site even as a zip file.

Thanks
John
0
 
LVL 13

Accepted Solution

by:
joechina earned 500 total points
ID: 21822341
Have you tried to move

 if (chkEditIsLockedOut.Checked == false) { UserDetails.UnlockUser(); }

down after the update?

UnlockUser might update the database first(You can do a quick check), so when you update the user, the record status is different from when you get the user.
0
 

Author Closing Comment

by:Filtered
ID: 31467842
Thank you very much joechina that has done the trick :)
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question