Help with Creating a Class


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
 
Ad

Advertisements

K

Kevin Spencer

It helps if you tell us what the compiler error was. However, I did go
through your code, and found the following:

Public Sub New(Name as String)
Name = strName
End Sub

Note that the Sub is attempting to assign the private "strName" property to
the input parameter "Name" - I would think you rather wanted it the other
way round.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Ad

Advertisements

P

Paul Say

The Error I get is

error BC30451: Name 'ViewState' is not declared.
Dim 0 Object = ViewState(strName & "Selected")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top