ASP.NET - Unable to persist data between postbacks

O

Owen

Firstly, if this is the wrong newsgroup for my question, please direct me
elswhere and accept my apologies! It's a question about ASP.NET but also
uses VB.NET classes.

This is a little strange, but I feel I'm missing an obvious answer. Perhaps
you guru's can enlighten me?


I have webform. I also have a class, which includes the following
declaration and property:
____________

Protected _IRWKeyMilestones as IRWKeyMilestones

Public Property IRWKeyMilestones() As IRWKeyMilestones
Get
If _IRWKeyMilestones Is Nothing Then
_IRWKeyMilestones = New IRWKeyMilestones(Cascade, Me)
End If
Return _IRWKeyMilestones
End Get
Set(ByVal Value As IRWKeyMilestones)
_IRWKeyMilestones = Value
End Set
End Property
____________

The IRWKeyMilestones class is marked "<Serialisable()>" and inherits the
..net "Collection" class.

The IRWKeyMilestones collection is populated via the web form, that's not
important right now. When I refer to "IRWKeyMilestones" elsewhere in the
code, it gets it nicely from the above property as expected. And when I
change an IRWKeyMilestones item, it updates the collection nicely. So far,
so good.

I have a "Save" button on my web form, which calls a "Save" method, which
saves the collection to the database. Again, the details of that aren't
imporant right now. The point is, it works fine and the _IRWKeyMilestones
collection is persisted upon postback of the form.

Now, the problem:

I have another button, totally unrelated, elsewhere on my webform. This
button also causes a postback - to update other parts of the page. BUT
when this particular postback happens, it seems to obliterate
_IRWKeyMilestones; it sets it to Nothing. So all changes to the collection
are lost. I remind you, IRWKeyMilestones is *totally unrelated* to the
button being pressed.

Can anyone think of an obvious reason why _IRWKeyMilestones isn't being
persisted in the second instance? I thought putting "Protected" in front
of it was enough? Obviously not.

Help !

Thanks,
Owen

PS. replies cc'd via email appreciated
(e-mail address removed)
 
C

Cor Ligthert [MVP]

Owen,

A webform is never persistent. Notever what you do with a non shared class
(and with that is something special see below).

You can save data using a
viewstate (that will sent it with the page, I will not advice however there
are reasons to do that)
cache(which belong to all clients which are at that time active, so you have
to set a kind of indexing)
shared class(acts the same as the cache)
session(the most easy one to use)

The normal way is to fill a session if Not IsPostBack

And to fill your classes again if it is IsPostBack

I hope this helps,

Cor
 

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