Putting an object in session via a property in ASP.NET

Specktor

New Member
This seems like it might be a bad idea, but I can't figure out why:I have a class, cXYZ, with properties A, B and C. It also has a method 'sGetData' that loads those three properties from the database, and a method 'sSaveData' which saves it back.\[code\]class cXYZ public property A as string... public property B as string... public property B as string.. public sub sGetData()... public sub sSaveData()...end class\[/code\]A webform has the following property:\[code\]private property xyz() as cXYZget return session("myXYZ")end getset (value as cXYZ) session("myXYZ")=valueend setend property\[/code\]And the following events:\[code\]Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Loadif not ispostback() then xyz=new cXYZ()end ifend subProtected Sub ButtonLoad_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonLoad.Click //Can now reference the class txtA.text=xyz.A txtB.text=xyz.B txtC.text=xyz.Cend sub Protected Sub ButtonSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonSave.Click //Can now reference the class xyz.A=txtA.text xyz.B=txtA.text xyz.C=txtC.text xyz.sSaveData()end sub\[/code\]I can see some overhead with serializing/deserializing for each property reference- it might be worth doing this:\[code\] Protected Sub ButtonSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonSave.Click dim localxyz as cXYZ=xyz localxyz .A=txtA.text localxyz .B=txtA.text localxyz .C=txtC.text xyz=localxyzend sub\[/code\]Other than that, views on why this is good or bad? The class is not large, it maintains the form state. Webforms suck, etc is not very useful..
 
Back
Top