Session variable value resets

A

aamirghanchi

Hi, I need to know if anyone else came across this. The Session
variable value I set in a sortCommand event handler of a datagrid does
not hold on till the next sortcommand event handler and reverts back
to its original value, the one I had set it before in the previous
trip sortcommand event handler.

I am trying to implement bidirectional sorting on a datagrid by making
use of session variable Session("SDirection"). In the sortcommand
event handler I check for its value and change it to DESC if its ASC
and vice-versa as follows:
Session("SDirection") = IIf(Session("SDirection") = "ASC", "DESC",
"ASC")
For the sake of simplicity I am not checking for the column in the
above code ... just the direction.
It sorts the dgrid fine for that pass, but next time a column (or same
column) header is clicked then in the sortcommand handler I find the
value to be the same that it was before I had made the change.

In the web.config the session configuration looks like this:
<sessionState mode="InProc" cookieless="AutoDetect" timeout="20"/>

This app was originally in .Net 1.1 and was working perfectly fine
(and is on the 1.1 framework), but after converting it to 2.0 it has
lost this functionality.

If any one has had the same issue then please share.

thanks.
 
M

Mike Hofer

Hi, I need to know if anyone else came across this. The Session
variable value I set in a sortCommand event handler of a datagrid does
not hold on till the next sortcommand event handler and reverts back
to its original value, the one I had set it before in the previous
trip sortcommand event handler.

I am trying to implement bidirectional sorting on a datagrid by making
use of session variable Session("SDirection"). In the sortcommand
event handler I check for its value and change it to DESC if its ASC
and vice-versa as follows:
Session("SDirection") = IIf(Session("SDirection") = "ASC", "DESC",
"ASC")
For the sake of simplicity I am not checking for the column in the
above code ... just the direction.
It sorts the dgrid fine for that pass, but next time a column (or same
column) header is clicked then in the sortcommand handler I find the
value to be the same that it was before I had made the change.

In the web.config the session configuration looks like this:
<sessionState mode="InProc" cookieless="AutoDetect" timeout="20"/>

This app was originally in .Net 1.1 and was working perfectly fine
(and is on the 1.1 framework), but after converting it to 2.0 it has
lost this functionality.

If any one has had the same issue then please share.

thanks.

A couple of things I would look at right off the bat:

1. Double-check the *case* of the characters in the keys you're using
to reference the items in the session. I'm not sure if the code sample
above was pasted in, or typed from memory; I know I've run into issues
due to case-sensitivity with session keys. That is, Session("a") !=
Session("A").

2. Are you checking for the key's existence prior to retrieval? Try
setting a breakpoint, drop out to the command window in Visual Studio
and iterate over the Session.KeyNames collection and see if it's
there. It would be interesting to see if the key got dropped or
possibly overwritten.

Just a few things I can think of right off the top of my head.

Mike
 
G

Guest

It would seem to me that the easiest way to figure out what's happening is to
run this in debug mode with a breakpoint on your line of code that does the
check and makes the change to the Session variable's value.

You can examine the values and the logic each time your breakpoint is hit.
Peter
 
A

aamirghanchi

A couple of things I would look at right off the bat:

1. Double-check the *case* of the characters in the keys you're using
to reference the items in thesession. I'm not sure if the code sample
above was pasted in, or typed from memory; I know I've run into issues
due to case-sensitivity withsessionkeys. That is,Session("a") !=Session("A").

2. Are you checking for the key's existence prior to retrieval? Try
setting a breakpoint, drop out to the command window in Visual Studio
and iterate over theSession.KeyNames collection and see if it's
there. It would be interesting to see if the key got dropped or
possibly overwritten.

Just a few things I can think of right off the top of my head.

Mike- Hide quoted text -

- Show quoted text -

Thanks Mike,

I have replaced all occurrences of Session("SDirection") with
Session("SDirection") throughout the project through IDE so I can be
sure they all are of the same case.

Any way it is the same event handler that sets and then retrieves the
value in the next trip. therefore case sensitivity should not be an
issue.

Also I have looked for the clause "Session("SDirection") =" so that I
can be sure there is no other part of the code in between thats
changing the session value.

I am pretty sure that the key does not get dropped, as it is still
bringing up the old value and not totally nulling it (at least I am
not getting "object reference not set error")

thanks for the feedback again.
 
A

Aamir Ghanchi

Thanks Mike,

I have replaced all occurrences of Session("SDirection") with
Session("SDirection") throughout the project through IDE so I can be
sure they all are of the same case.

Any way it is the same event handler that sets and then retrieves the
value in the next trip. therefore case sensitivity should not be an
issue.

Also I have looked for the clause "Session("SDirection") =" so that I
can be sure there is no other part of the code in between thats
changing the session value.

I am pretty sure that the key does not get dropped, as it is still
bringing up the old value and not totally nulling it (at least I am
not getting "object reference not set error")

thanks for the feedback again.- Hide quoted text -

- Show quoted text -

Found the solution:
The dgrid was being sorted twice hence the Sortcommand was being
called twice and I would see the final sorted result. Session variable
SDirection was being set twice first from ASC to DESC and then back
again to ASC. therefore I would not see any change in the sort order.
All this was happening because the sortcommand event handler was
mentioned twice. Once declared in the onSortCommand attribute of the
datagrid in te aspx page and then again by adding "Handles
dgrid.SortCommand" in the definition of the actual event handler in
codefile.

Thanks.
 
A

Aamir Ghanchi

Thanks Mike,

I have replaced all occurrences of Session("SDirection") with
Session("SDirection") throughout the project through IDE so I can be
sure they all are of the same case.

Any way it is the same event handler that sets and then retrieves the
value in the next trip. therefore case sensitivity should not be an
issue.

Also I have looked for the clause "Session("SDirection") =" so that I
can be sure there is no other part of the code in between thats
changing the session value.

I am pretty sure that the key does not get dropped, as it is still
bringing up the old value and not totally nulling it (at least I am
not getting "object reference not set error")

thanks for the feedback again.- Hide quoted text -

- Show quoted text -

Found the solution:
The dgrid was being sorted twice hence the Sortcommand was being
called twice and I would see the final sorted result. Session
variable
SDirection was being set twice first from ASC to DESC and then back
again to ASC. therefore I would not see any change in the sort order.
All this was happening because the sortcommand event handler was
mentioned twice. Once declared in the onSortCommand attribute of the
datagrid in te aspx page and then again by adding "Handles
dgrid.SortCommand" in the definition of the actual event handler in
codefile.

I checked the 1.1 code which still sorts fine even it had the event
handler mentoned twice. Is this new behavior in 2.0 a bug or by
design?

Thanks.
 

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

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top