By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,916 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,916 IT Pros & Developers. It's quick & easy.

ASP.NET - unable to persist data between postbacks

P: n/a
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
ow************@mantix.com
Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
"Owen" wrote:
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
ow************@mantix.com

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.