persistance of Classes

N

Namshub

I'm A client server developer by trade and i'm moving my skill set slowly
over to ASP.NET.

One question, I have a class, that i populate on a postback... I want to
keep this data persistant though other multiple postbacks.

What is the desired mechanism to use this.

I'm using the following code but not sure if this is the appropriate
solution to the problem

Private PatientDetails As Patient

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If ViewState("Patient") Is Nothing Then

PatientDetails = New Patient

viewstate.Add("Patient", PatientDetails)

Else

PatientDetails = New Patient

PatientDetails = viewstate("Patient")

End If

Private Function SearchPAS() As Boolean ' called by a button clik

PASmsg = PatientDetails.GetPASDetails(cSite, byCriteria, lbText.Text)
'which fills all the property fields

viewstate("Patient") = PatientDetails

end function
 
N

Namshub

Adtmitedly this doesn't work yet because its not serialized, i'm also
working on how to do that as well
 
E

Eran Kampf

Hi,
You have several methods of persisting data between postbacks:
1. Using the view state - The entire viewstate data is serialized to a
hidden input field in the output html and then deserialized at postback.
This is good if your object does not contain large amounts of data
(serialization to the output html = large html output = slow loading for the
user).
2. Using the session state. This way the data is saved on the server between
postbacks (there are 3 different session state configurations you should
read about in MSDN).
 
K

Kevin Spencer

As long as your Patient class is serializable (which it apparently is), and
the extra HTML it adds to the document doesn't slow the response time down
too much, it's an excellent way to accomplish your goal. :)

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top