My attempt below, is giving object reference, why? how to solve?
My attempt below, is giving object reference, why? how to solve?
Your problem is in Page_Load
, because every time a postback is done your Page_Load
method is called and is always reloading your data.
To avoid reloading the data in PostBack
simply do this:
Protected Sub Page_Load(ByVal sender as Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
PreencheListaUsuarios()
PreencheListaPerfis()
End If
End Sub
This way when it reaches btnDeletarPerfil_click
the data in the listbox will be normal. :)
If (lbPerfis.Items.Count = 0) = False Then
If (lbPerfis.SelectedItem Is Nothing) = False Then
roles.DeleteRole(lbPerfis.SelectedItem.Text.ToString)
End If
End If