Domanda

Sto cercando di aggiornamento delle informazioni dell'utente e di ottenere il seguente errore:

Riferimento a un oggetto non impostato su un' istanza di un oggetto.Descrizione:Un eccezione non gestita durante l' l'esecuzione di web corrente richiesta.Si prega di rivedere la traccia dello stack per ulteriori informazioni sull'errore e dove ha avuto origine nel codice.

Dettagli Eccezione:Sistema.NullReferenceException:Oggetto di riferimento non impostato su un'istanza di un oggetto.

Fonte Di Errore:

Linea 20:'senza parametri costruttore Linea 21:Linea 22:
utente.E-mail = DirectCast(e.NewValues(0), Stringa) Linea 23:utente.Commento = DirectCast(e.NewValues(1), Stringa) Linea 24:utente.IsApproved = CBool(e.NewValues(2))

L' .codice vb è:

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

Qui di seguito è l' .codice aspx per la 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

Qualsiasi idea di come posso risolvere questo?

Qualsiasi aiuto sarebbe molto apprezzato.

Grazie

È stato utile?

Soluzione

La prima ipotesi, senza vedere il codice più, sarebbe che il user variabile è null.Hai impostato quando hai eseguito il rendering della pagina?Presumo che il tuo codice qui sopra è un postback e così user perso valore.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top