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)
 
G

Guest

On a postback/callback, the page will re-instantiate all of it's member
variables. If you want to persist state/data across postbacks/callbacks then
you will need to save the state/data to the
viewstate/session/cache/application datastores.

Remember, most of these stores will timeout and clear your data. So, check
to make sure that they are still there before accessing them. Otherwise, you
will get an object reference error.
--
Staff Consultant II
Enterprise Web Services
Cardinal Solutions Group

Future Business Model
Loan Origination Services
National City Mortgage
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top