P
Paul Say
At Present I have several properties of a page that are use to store
variables between page calls in the pages view state eg.
Property View() as String
Get
Dim o As Object = ViewState("View")
If o Is Nothing Then
Return String.Empty
End If
Return CStr(o)
End Get
Set(ByVal Value As String)
ViewState("View") = Value
End Set
End Property
Property Selected() As String
Get
Dim o As Object = ViewState("Selected")
If o Is Nothing Then
Return String.Empty
End If
Return CStr(o)
End Get
Set(ByVal Value As String)
ViewState("Selected") = Value
End Set
End Property
What I would like to do to make the page cleaner and code reusable is to
roll these properties into a class to enable the following
Dim Job as new listState
Job.View = xxx
Job.Selected = 1
something = Job.View
Dim SubJob as new listState
SubJob.View = xxx
SubJob.Selected = 2
Etc...
I tried createing the following class, however it wouldn't compile, is there
a better approach that will work?
Imports System
Imports System.Web
Imports System.Web.UI
Namespace mySpace
Public Class ListState
Private strName as String
Public Sub New(Name as String)
Name = strName
End Sub
Property Selected() As String
Get
Dim o As Object = ViewState(strName & "Selected")
If o Is Nothing Then
Return String.Empty
End If
Return CStr(o)
End Get
Set(ByVal Value As String)
ViewState(strName & "Selected") = Value
End Set
End Property
End Class
End Namespace
variables between page calls in the pages view state eg.
Property View() as String
Get
Dim o As Object = ViewState("View")
If o Is Nothing Then
Return String.Empty
End If
Return CStr(o)
End Get
Set(ByVal Value As String)
ViewState("View") = Value
End Set
End Property
Property Selected() As String
Get
Dim o As Object = ViewState("Selected")
If o Is Nothing Then
Return String.Empty
End If
Return CStr(o)
End Get
Set(ByVal Value As String)
ViewState("Selected") = Value
End Set
End Property
What I would like to do to make the page cleaner and code reusable is to
roll these properties into a class to enable the following
Dim Job as new listState
Job.View = xxx
Job.Selected = 1
something = Job.View
Dim SubJob as new listState
SubJob.View = xxx
SubJob.Selected = 2
Etc...
I tried createing the following class, however it wouldn't compile, is there
a better approach that will work?
Imports System
Imports System.Web
Imports System.Web.UI
Namespace mySpace
Public Class ListState
Private strName as String
Public Sub New(Name as String)
Name = strName
End Sub
Property Selected() As String
Get
Dim o As Object = ViewState(strName & "Selected")
If o Is Nothing Then
Return String.Empty
End If
Return CStr(o)
End Get
Set(ByVal Value As String)
ViewState(strName & "Selected") = Value
End Set
End Property
End Class
End Namespace