context problem

H

Hugo Flores

Often people post questions about how did they loose their context
between pages, and the more common cause is that they don't store the
context on the viewstate upon postbacks.
Mine is the other way around. Even though I don't fill the context
object, I still get it after the Page Load event. May be I'm not
understanding the context object quite well.

Next is the code, and I know this wouldn't regularly transfer the
context to the next page, but that is not what I'm trying to figure
out.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If IsPostBack Then
oCustomer = viewstate("Customer")
Else
oCustomer = New Customer
oCustomer = context.Items("Customer")

viewstate("Customer") = oCustomer
End If
End Sub ====> Breakpoint here

Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdNext.Click =====> Breakpoint here
Server.Transfer("NextPage.aspx")
End Sub

The first time I load this page, I get the Customer object from the
context sent on the previous page. Then I click the Next button, and on
debugging mode I put a breakpoint on the End Sub of the Page Load
event. Here context.Items("Customer") is Nothing. Nothing wrong there,
but I also have a breakpoint on the declaration of the cmdNext Click
event, and here he context.Items("Customer") has been misteriously
filled with a Customer object.
Do anybody know, what is going on?

Thanks
 
K

Karl Seguin

I haven't been able to reproduce in either c# or vb.net for either 1.1 or
2.0.

Could it be code elsewhere? Could a reference to Context.Items("Customer")
exist somewhere which is being instantiated?

by the way:
oCustomer = New Customer
is a useless line
 
H

Hugo Flores

Thanks for your answer Karl,

There are other references to the Context.Items("Customer") but the
occur after the Click event. So when I click a button, goes to page
load, goes to postback, and then to the Click event. So why is this
context being filled after Page Load event has finished and filled
exactly when the Click event is called. I also managed to debug another
context variable, that just contained a string, and that variable,
still had nothing when the breakpoint was on the Click event. So could
it also be, because the Context.Items("Customer") contains a
seralizable object?
 
K

Karl Seguin

I've tried with a serializable object, and no go.

I still think it's a floating reference. Between Load and Click there's a
Changed event...do you have any onSelectedIndexChanged or onTextChanged or
anything which play with the Context.Items("Customer")

Karl
 
H

Hugo Flores

The only two events that I have are Click events on two buttons. One
thing to mention though, is that the form has an
encType="multipart/form-data". Because it's also used to upload a photo
of the customer.
 

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,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top