Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Session variable value resets

152 views
Skip to first unread message

aamirg...@gmail.com

unread,
Apr 3, 2007, 12:03:19 PM4/3/07
to
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.

Mike Hofer

unread,
Apr 3, 2007, 2:08:17 PM4/3/07
to

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

aamirg...@gmail.com

unread,
Apr 3, 2007, 4:25:09 PM4/3/07
to
On Apr 3, 1:08 pm, "Mike Hofer" <kchighl...@gmail.com> wrote:
> On Apr 3, 12:03 pm, aamirghan...@gmail.com wrote:
>
>
>
>
>
> > Hi, I need to know if anyone else came across this. TheSession
> > variablevalueI set in a sortCommand event handler of a datagrid does

> > not hold on till the next sortcommand event handler and reverts back
> > to itsoriginalvalue, 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 ofsessionvariableSession("SDirection"). In the sortcommand
> > event handler I check for itsvalueand 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
> >valueto be the same that it was before I had made the change.
>
> > In the web.config thesessionconfiguration 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 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.

Message has been deleted

Aamir Ghanchi

unread,
Apr 4, 2007, 12:11:40 PM4/4/07
to
> 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.


0 new messages