I am trying to update a user information and get the following error:
Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 20: 'parameterless constructor Line 21: Line 22:
user.Email = DirectCast(e.NewValues(0), String) Line 23: user.Comment = DirectCast(e.NewValues(1), String) Line 24: user.IsApproved = CBool(e.NewValues(2))
The .vb code is:
Protected Sub UserInfo_ItemUpdating(ByVal sender As Object, ByVal e As DetailsViewUpdateEventArgs)
        'Need to handle the update manually because MembershipUser does not have a
        'parameterless constructor  
        user.Email = DirectCast(e.NewValues(0), String)
        user.Comment = DirectCast(e.NewValues(1), String)
        user.IsApproved = CBool(e.NewValues(2))
        Try
            ' Update user info:
            Membership.UpdateUser(user)
            ' Update user roles:
            UpdateUserRoles()
            UserUpdateMessage.Text = "Update Successful."
            e.Cancel = True
            UserInfo.ChangeMode(DetailsViewMode.[ReadOnly])
        Catch ex As Exception
            UserUpdateMessage.Text = "Update Failed: " + ex.Message
            e.Cancel = True
            UserInfo.ChangeMode(DetailsViewMode.[ReadOnly])
        End Try
    End Sub
Below is the .aspx code for the detailView:
 Protected Sub UserInfo_ItemUpdating(ByVal sender As Object, ByVal e As DetailsViewUpdateEventArgs)
        'Need to handle the update manually because MembershipUser does not have a
        'parameterless constructor  
        user.Email = DirectCast(e.NewValues(0), String)
        user.Comment = DirectCast(e.NewValues(1), String)
        user.IsApproved = CBool(e.NewValues(2))
        Try
            ' Update user info:
            Membership.UpdateUser(user)
            ' Update user roles:
            UpdateUserRoles()
            UserUpdateMessage.Text = "Update Successful."
            e.Cancel = True
            UserInfo.ChangeMode(DetailsViewMode.[ReadOnly])
        Catch ex As Exception
            UserUpdateMessage.Text = "Update Failed: " + ex.Message
            e.Cancel = True
            UserInfo.ChangeMode(DetailsViewMode.[ReadOnly])
        End Try
    End Sub
Any idea how i can sort this?
Any help would be greatly appreciated.
Thanks
                        
My first guess, without seeing more code, would be that your
uservariable is null. Did you set it when you rendered the page? I assume your code above is a postback and souserlost it's value.