473,394 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Use of user created classes across pages

RSH
I am struggling with a concept I'm not really finding a lot of in depth
articles on but Im sure others have had similar issues.

What is the best practice when it comes to persisting custom created objects
during a user's session?

I have created several objects that when run with an Out of Process session
state they cause the dreaded "Unable to serialize the session state. Please
note that non-serializable objects or MarshalByRef objects are not permitted
when session state mode is 'StateServer' or 'SQLServer'. " exception.

In the past I have created a base object that contained all of the
serializable properties, then create a concrete class underneath and
basically stripped the base class off and saved it in a session variable and
then "bolted" it back up when needed on other pages (.net 1.1). But now
that I am at the point where I need to develop an application I am wondering
how to deal with custom objects and persisting them properly.

Im struggling using OOP techniques for the web. How are other people
handling these techniques?

This is an example of the class that wont serialize, but I need to reference
it throughout the user's session:

Thanks,
Ron
<Serializable()Public Class CompanyBase

#Region "Member Variables"

Private m_ID As System.Int32

Private m_OfficeID As System.String

Private m_CompanyID As System.String

Private m_AliasID As System.String

Private m_CompanyName As System.String

Private m_DataSource As DataSourceType

Private m_oData As BaseDataClass

#End Region

#Region "Member Properties"

Public Property ID() As System.Int32

Get

Return m_ID

End Get

Set(ByVal Value As System.Int32)

m_ID = Value

End Set

End Property

Public Property OfficeID() As System.String

Get

Return m_OfficeID

End Get

Set(ByVal Value As System.String)

m_OfficeID = Value

m_CompanyDataset.Tables(0).Rows(0).Item("OfficeID" ) = Value

End Set

End Property

Public Property CompanyID() As System.String

Get

Return m_CompanyID

End Get

Set(ByVal Value As System.String)

m_CompanyID = Value

End Set

End Property

Public Property AliasID() As System.String

Get

Return m_AliasID

End Get

Set(ByVal Value As System.String)

m_AliasID = Value

End Set

End Property

Public Property CompanyName() As System.String

Get

Return m_CompanyName

End Get

Set(ByVal Value As System.String)

m_CompanyName = Value

End Set

End Property

#End Region

#Region "Constructor"

Public Sub New()

End Sub

Public Sub New(ByVal companyID As String)

m_CompanyID = companyID

m_DataSource = DataSourceType.SQLServer

DataSourceBuilder()

End Sub

#End Region

#Region "Member Methods"

Private Sub DataSourceBuilder()

If m_DataSource = DataSourceType.XML Then

m_File = HttpContext.Current.Request.PhysicalApplicationPat h & Me.CompanyID
& "_Company.xml"

m_oData = DataFactory.GetDataClass(m_File, DataSourceType.XML)

m_oData.ConnectionString = m_File

m_oData.PrimaryKey = "ID"

ElseIf m_DataSource = DataSourceType.Access Then

m_File = HttpContext.Current.Request.PhysicalApplicationPat h & "Global.mdb"

m_oData = DataFactory.GetDataClass(m_File, DataSourceType.Access)

m_oData.ConnectionString = m_File

m_oData.PrimaryKey = "ID"

m_oData.SQLString = "select * from companies WHERE CompanyID = '" &
m_CompanyID & "'"

ElseIf m_DataSource = DataSourceType.SQLServer Then

m_oData = DataFactory.GetDataClass("Global", DataSourceType.SQLServer)

m_oData.SQLString = "select * from Global.dbo.companies WITH(NOLOCK) WHERE
CompanyID = '" & m_CompanyID & "'"

m_oData.PrimaryKey = "ID"

End If

m_CompanyDataset = m_oData.GetDataSet()

BindProperties()

End Sub

Private Sub BindProperties()

Dim oDr As DataRow

If Not CompanyID Is Nothing Then

If m_CompanyDataset.Tables(0).Rows.Count 0 Then

oDr = m_CompanyDataset.Tables(0).Rows(0)

ID = IIf(Not IsDBNull(oDr("ID")), oDr("ID"), Nothing)

OfficeID = IIf(Not IsDBNull(oDr("OfficeID")), oDr("OfficeID"), Nothing)

CompanyID = IIf(Not IsDBNull(oDr("CompanyID")), oDr("CompanyID"), Nothing)

AliasID = IIf(Not IsDBNull(oDr("AliasID")), oDr("AliasID"), Nothing)

CompanyName = IIf(Not IsDBNull(oDr("CompanyName")), oDr("CompanyName"),
Nothing)

End If

End If

End Sub

Public Sub UpdateDataSet()

Dim oDr As DataRow

If m_CompanyDataset.Tables(0).Rows.Count 0 Then

oDr = m_CompanyDataset.Tables(0).Rows.Find(ID)

oDr("OfficeID") = IIf(OfficeID <Nothing, OfficeID, DBNull.Value)

oDr("CompanyID") = IIf(CompanyID <Nothing, CompanyID, DBNull.Value)

oDr("AliasID") = IIf(AliasID <Nothing, AliasID, DBNull.Value)

oDr("CompanyName") = IIf(CompanyName <Nothing, CompanyName, DBNull.Value)

End If

End Sub

Public Function GetOutput() As String

Dim sb As New StringBuilder

For Each prop As PropertyInfo In Me.GetType.GetProperties

sb.Append(prop.Name & " - " & prop.GetValue(Me, Nothing) & "<br>")

Next

Return sb.ToString

End Function

Public Sub SaveChanges()

UpdateDataSet()

m_oData.SaveDataSet(m_CompanyDataset)

End Sub

#End Region

End Class
Jun 11 '07 #1
0 1040

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ani | last post by:
Hi, I need to carry the user input across pages and then at the end insert all the values into the DB. How do I best accomplish this task in ASP.Net. I am a novice , please give me some simple...
1
by: Jordan | last post by:
I'm converting a section of our website into the .NET framework (the rest will follow sooner or later). I'd certainly like to maintain all the dynamic capabilities as well as implement some new...
7
by: jsale | last post by:
I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app i have made is running on IIS v6 and consists of a number of pages that allow the user to read information from the...
9
by: McGeeky | last post by:
Is there a way to get a user control to remember its state across pages? I have a standard page layout I use with a header and footer as user controls. Each page uses the same layout by means of...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.