PDA

View Full Version : Session Variable changes


ScottInTexas
06-13-2003, 02:36 PM
I have a variable which I need to pass from one ASP to another. I am using a session variable for it. But it doesn't work as expected.

I have an session_onStart sub in the global.asa and I initialize the variable there. A javascript calls an asp and passes a value that is then assigned to the session variable. This asp may call (using response.redirect) another asp in which the variable is required.

This works every time for me on the intranet. But on another user's computer the variable is set once and never changes, even though the whole process is run as described (with the exception of the asa) .

javaScript calls getData.asp to start

'Month or Quarter
session("dataPeriod")=Request.QueryString("Period")
plantName=Request.QueryString("plant")

Select Case plantName
Case "All Plants"
Response.Redirect "AllData.asp"
Case "Business Total"
Response.redirect "TotalActMaint.asp"
End Select

'In either of the above asps

Function Test()
Dim LineStr
cnxn=GetConn
prd=session("dataPeriod")
response.write("In TotalActMaint.asp. dataPeriod=" & prd)

etc.



As I said, if the user selects "month from the drop down in the initial html the variable is set to month all the way through and is used to get the proper data. But if the user then selects "quarter" he still gets month because the variable didn't change.

Thanks

raf
06-13-2003, 03:05 PM
Are you sure there is no typo involved or that the sesionvariable isn't a constant? And after you change, you post to the first page, right? (not to alldata.asp or totalactmain.asp) And you are sure you dant see a cached page ?
try

response.write (Now())
response.write("<br />initial sessionvariable on pageload = " & session("dataPeriod"))
response.write("<br />value from duerrystrin = " & Request.QueryString("Period"))
session("dataPeriod")=Request.QueryString("Period")
response.write("<br />sessionvariable after processing = " & session("dataPeriod"))
response.end

ScottInTexas
06-13-2003, 03:26 PM
I am certain about the spelling. I also have prompts in the two places where the variable is read from the session. On my computer the prompt displays the correct value. On his computer it remains the same.

One thing I haven't been able to check is that the first page called in the browser is an html. When the user selects from the drop down the first asp is called. Maybe I should change the name of the first page to an asp page so that the asa is called before the need for the session variable. Unfortunately I have a meeting to go to now and I'll have to come back in a couple of hours.

Thanks for your time.

glenngv
06-16-2003, 01:57 AM
yes, you should change the name of htm to asp. global asa is not executed if the first page accessed is an .htm page, or any non-asp page for that matter.

ScottInTexas
06-19-2003, 02:07 PM
Thanks for your reply. I would have responded sooner but had to go out of town for two days.

The program flows like this;

Web page (formerly .htm) opens and has two drop downs, plant and period. When the user has select from both of the drop downs an asp is called using

IFrame.location="getData.asp?plant=" + strPlant + "&period=" + strPeriod;

getData places the value of the period in a session variable with session("dataperiod")=request.querystring(period)
because it is used to determine which subsequent asp to call, either AllPlants + quarter or month, or any plant quarter or month. I used two different asps based on those selections.

The problem has been that the period would not pass through to the other asps using session("dataperiod"). But only on certain user's machines. On my machine there was no problem, on the secretary's machine there was no problem on my bosses machine it didn't work and another coworker's machine it didn't work.

Say she selected the period 'month' then the first chart would show month data but if she switched to quarter the chart would redraw with month data. Then if she switched again to month data the chart would show with quarter data.

All I did with the sub onSession_Start() was to put session("dataperiod")=""

I assumed that when the function in the html called the getData asp then the global asa would run and that I had to create the variable there.

As I said, this works properly on some machines and not on others. I don't know how to debug that kind of problem. Since this is a global application I cannot rely on what people have for browser settings (other than IE5 or above and all machines are windows 98 connected to the company intranet).

The end result is to put everything into one large asp and it will run slower as a result. Since I am always pressed for time, the solution to this problem is academic. Next time I'll use whatever I can learn from this.


Anyway, thanks again.

raf
06-19-2003, 02:49 PM
The global.asa wount be the problem. Even if this onSession_Start() sub isn't processed, the sessionvariable would haven been set. (i suppose that request.querystring(period) is a typo --> need double quotes)

I don't quite understand why you just don't use a form that you post to getData.asp to get the values from the forms collection. If you wan't to debug it, just print each variable after it's value (should have been) changed and trachk down here it isn't changed at some times.

The end result is to put everything into one large asp and it will run slower as a result.

Not so sure about that.
Recently finished a page of more then 1000 lines of code, 8 selects (some with up to 7-tablejoins) and quite some computing, and even that doesn't take much more then a second to get processed.

ScottInTexas
06-20-2003, 02:05 PM
Thanks Raf, you're right. There was no visible performance issue. I thought it would be slow.

I don't quite understand why you just don't use a form that you post to getData.asp to get the values from the forms

Isn't that what I am doing? When I have the line ...location=myfile?plant= etc., am I not "Posting" to the asp?

raf
06-20-2003, 04:41 PM
not sure your posting.

in the early days, forms were posted through the querystring (the current 'get' method in the <form> So basically posting a form was the same as requesting the page you post to, with all variabels and values in the querystring.

I think you now request that page.

If you have an onchange=submit(); or so in the form or a formelement, then you are 'submitting the form' --> posting the data to your page in that is specified as value in the action of your <form>

ScottInTexas
06-20-2003, 05:02 PM
OK. I am not using "submit", but the variables are still passed and they are gathered up in the same way as with "post" i.e. newvar=request.querysring("MyVar").

In any case, the page works now (all-in-one design) and it is up on the intranet. I hope that I am done with it! It has been a PITA all the way. Of course, mostly because of the demands of my boss. It was a very frustrating project.

I appreciate your responses. Thank you.