Quote:
Public Class StudentNames
Inherits System.Web.UI.Page
Public List As New Generic.List(Of String)
Every request to your page, including a post-back, will create a new instance of your page class to process the request.
Anything stored in a field within that class will not be persisted between requests.
You'll need to store your list in
ViewState
for the changes to persist between requests.
Public Property List As Generic.List(Of String)
Get
Dim value As String() = DirectCast(ViewState("List"), String())
If value Is Nothing Then Return New Generic.List(Of String)
Return New Generic.List(Of String)(value)
End Get
Set(ByVal value As Generic.List(Of String))
If value Is Nothing Then Throw New ArgumentNullException()
ViewState("List") = value.ToArray()
End Set
End Property
ASP.NET State Management Overview | Microsoft Docs[
^]