Persistance

  • Thread starter Thread starter CCORDON
  • Start date Start date
C

CCORDON

I have some classes that contain my objects...say..... Client...with all his
properties, Methods & Events. I use this on my web pages like this.


Dim MyClient as New Client(IdCorporation)

This because I need the information of that client as a reference.

Then I use:

If not page.IsPostBack then

Dim MyOtherClient as New Client ()
This is created just to use a function from that class:
MyOtherClient.Add (Name, Address, City, Zip, Phone)

Endif

The problem is that when a postback occurs...MyOtherClient = MyClient.

How should this be handled?

Thanks
 
CCORDON said:
I have some classes that contain my objects...say..... Client...with all his
properties, Methods & Events. I use this on my web pages like this.

Dim MyClient as New Client(IdCorporation)

This because I need the information of that client as a reference.

Then I use:

If not page.IsPostBack then

Dim MyOtherClient as New Client ()
This is created just to use a function from that class:
MyOtherClient.Add (Name, Address, City, Zip, Phone)

Endif

The problem is that when a postback occurs...MyOtherClient = MyClient.

How should this be handled?


What you posted seems impossible, no where are the two related to eachother
in your posted code. Perhaps you need to show more of what you are using....

LFS
 
Here is the code. Thank you for your help

Imports Vivo.DBAccess

Public Class CorporacionesMod

Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Protected WithEvents lblUserInfo As System.Web.UI.WebControls.Label

Protected WithEvents cmdLogOff As System.Web.UI.WebControls.ImageButton

Protected WithEvents RequiredFieldValidator2 As
System.Web.UI.WebControls.RequiredFieldValidator

Protected WithEvents txtNombre As System.Web.UI.WebControls.TextBox

Protected WithEvents cmdSave As System.Web.UI.WebControls.Button

Protected WithEvents ValidationSummary1 As
System.Web.UI.WebControls.ValidationSummary

'NOTE: The following placeholder declaration is required by the Web Form
Designer.

'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeComponent()

End Sub

#End Region

Private Shared objCorporacion As Corporacion

Private Shared MyUser As New User

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

'Put user code to initialize the page here

If Session("LoggedOn") = False Then

Response.Redirect("../UserLogin.aspx")

Exit Sub

End If

MyUser = CType(Session("User"), User)

Dim MyCorp As New Corporacion(MyUser.IdCorporacion)

lblUserInfo.Text = MyUser.NombreCompleto & "<BR>" & MyCorp.Nombre

If MyUser.Super = False Then

Response.Redirect("NoAccess.aspx")

End If

If Not (Page.IsPostBack) Then

objCorporacion = New Corporacion(Request.Params("IdCorporacion"))

txtNombre.Text = objCorporacion.Nombre

End If

End Sub

Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdSave.Click

Session("ResultMessage") = objCorporacion.Update(objCorporacion.ID,
txtNombre.Text)

Response.Redirect("Result.aspx?RedirectPage=Corporaciones.aspx")

End Sub

Private Sub cmdLogOff_Click(ByVal sender As System.Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles cmdLogOff.Click

Session("LoggedOn") = False

Session.Abandon()

Response.Redirect("../Gracias.aspx")

End Sub

End Class



Thanks,
 
CCORDON said:
Here is the code. Thank you for your help

OK, how have you determined the problem?

I did not see any assignment like that in the code you posted. The obvious
conclusion is that the two were not made equal to eachother, so I have to
ask, how are you determining that they are equal?

LFS
 
Thanks for your repply.

I stepped though the code and noticed that when I hit the Save button, it
makes a postback, at that time lets say that objCorporacion.Id has a value
of 5 and all the information for that record, and MyCorp.Id has a value of 1
and all the information for that record, but when it hits the line that
says: "If Not (Page.IsPostBack) Then" I checked both their values and now
appear to have Id = 1.

Thanks again.
 
C Cordon,

Persistency exists in a webpage only in a cache in a shared session, in the
viewstate.items or in the session.items.

The first two belongs to the application and exist only as long as the
application exist, which means as long that there are clients active with
that application. All the information in those two is shared by all active
clients. When you want to use those for individual users, you should index
all items you use in that shared class or cache by as example a session
index or a cookie index.

Only the session and the viewstate belong to the clientsession. Where the
viewstate goes over the line and comes back. For both you should serialize
your data first, for what a dataset is very easy to use, because that is
standard for that.

I hope this helps something?

Cor
 
CCORDON said:
Thanks for your repply.

I stepped though the code and noticed that when I hit the Save button, it
makes a postback, at that time lets say that objCorporacion.Id has a value
of 5 and all the information for that record, and MyCorp.Id has a value of 1
and all the information for that record, but when it hits the line that
says: "If Not (Page.IsPostBack) Then" I checked both their values and now
appear to have Id = 1.

When I have a particularly difficult problem, I will try to remove the problem from
all the surrounding code by just adding what is needed to show the problem, to
a new project. Some times, just doing that much helps to locate what the cause
was and allows me to fix it up. If not, then more debugging would take place on
the reduced code, rather than the whole application.

Or, you might turn on Tracing, and add trace statements to help you find
what is happening and when. For more info on tracing, check out this link:
http://msdn.microsoft.com/library/d...n-us/cpguide/html/cpcontracefunctionality.asp


HTH
LFS
 

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

Back
Top