Weird behavior on page when trying to retrieve data from Session

G

Guest

Hi everybody
I have a session on my vb.net web applications first page to store an one
dimensional array:

dim myAry(2) As String
myAry(0) = xVal
myAry(1) = yVal
HttpContext.Current.Session("mySession") = myAry

so far so good. Then I want to retrieve data from this session on the next
page:

dim myAry() As String
arySec = CType(HttpContext.Current.Session("mySession"), String())

dim myVal = myAry(0).ToString

This works fine when there is no error on the page but if there is any
regarding other line of codes that I've added later, it generates this error:

System.NullReferenceException: Object reference not set to an instance of an
object

and it shows my 'Response.write(strQ)' statement on the page.

Any ideas of why this happens and how I can fix it? I appreciate any help.

ASPSha
 
C

Cor Ligthert [MVP]

Kash,

Are you sure that this is working on your next page?
dim myAry() As String
arySec = CType(HttpContext.Current.Session("mySession"), String())
dim myVal = myAry(0).ToString

MyAray is an empty array.

Did you not wanted to use arySec or something as

dim myval as string = DirectCast(Session("mySession"),string())(0)

I hope this helps,

Cor
 
G

Guest

Cor:
thanks for your comment. Regarding the arySec, it was a typo and yes it has
the value when I retrieve the Session's value.
But I believe that the reason for generating the NullReferenceException
error has nothing to do with my array or session or others! I spent a lot of
time today on this and I find out that I'm not able to use "response.write"
on my code behind page anywhere when I want to grab a value quickly or look
at the query etc.! Does any body know why this happens? This happens only on
this project and I used to do this on all other projects and have never seen
something like this before. It has something to do with Response object!
This also happens when I put something like:
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1)) on code behind page
too!
Any comments? I do appreciate all your help.

Kash
 

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