
April 26th, 2003, 06:52 AM
|
|
Junior Member
|
|
Join Date: Apr 2003
Location: Belgium, Poperinge
Posts: 12
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Session variable strange behaviour
hi,
i seem to have a problem with my session variables.
I have a session variable called "nbr". This variable remembers a position for me.
This is needed for a previous and next button.
I start with the initial value of 1.
When the user clicks next, I add 10 to the session variable.
So this makes the session variable nbr equal to 11.
I then reload the page to retrieve my neccessary data.
In reloading the page I retrieve the value of the session variable and the value of it is 1.
I do not understand why he doesn't remember the correct value.
- Could it have something to do with not caching the page?
- Or something else?
I also have the same behaviour with an other session variable. ("Count"). This one knows how much items there are.
I have changed the code so when the page needs to be reloaded than I pass the "nbr" variable with the loadpage.asp. So in that way I can grab the variable with request.querystring.
That works also fine until I click back after clicking forward. If then I click back forward then It will not respond because my "nbr" variable hasn't changed. But I changed It.
The code is as follows.
PHP Code:
<HTML>
<head>
<title>Link page</title>
<%@Language="VBScript"%>
<%
Response.Expires = 60
Response.Expiresabsolute = Now() - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"
Session("filter") = request.querystring("filter")
dim sConn
Dim oConn
Set oConn = Server.CreateObject("ADODB.Connection")
if request.querystring("table") <> "" then
session("tablename") = request.querystring("table")
end if
sConn = "provider=Microsoft.jet.oledb.4.0; data source = " & Server.MapPath("/") & "\drweirdoproductions.mdb"
function loadLinks(sTableName)
Dim oRS
Dim collects
dim returnString
if request.querystring("nbr") = "" then
Session("nbr") = 1
else
Session("nbr") = request.querystring("nbr")
end if
returnString = "<div name=""moveBack"" style=""background-color: transparent; border: Black; width: 164; height: 32; background-image: url(images/linkbutton.gif);color:white; text-align: center; vertical-align: baseline; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-style: normal; font-size: xx-small; padding-top: 8;"" onClick=""moveBack();"">Back</div>"
Set oRS = Server.CreateObject("ADODB.Recordset")
if oConn.State = adStateClosed then
oConn.Open sConn
end if
oRS.Open "SELECT * FROM [" & sTableName & "] WHERE filter = '" & Session("filter") & "' AND seqnbr >= " & Session("nbr") & " AND seqnbr <= " & Session("nbr") + 10 & " ORDER BY Name" , oConn, 2, 3
If not oRS.EOF Then
Session("Count") = oRS("filterCount")
Do While Not oRS.EOF
returnString = returnString & "<div name=" & oRS("id") & " style='background-color: transparent; border: Black; width: 164; height: 32; background-image: url(images/linkbutton.gif);color:white; text-align: center; vertical-align: baseline; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-style: normal; font-size: xx-small; padding-top: 8;' onClick=openLink(this.childNodes) onMouseOver=setComment(this.childNodes) onMouseOut=unsetComment()>"
' *** Index = 0
returnString = returnString & "<input type=hidden name=""" & oRS("id") & "comment"" value=""" & oRS("Comment") & """>"
' *** Index = 1
returnString = returnString & "<input type=hidden name=""" & oRS("id") & "link"" value=""" & oRS("Url") & """>"
' *** Index = 2
returnString = returnString & "<input type=hidden name=""" & oRS("id") & "title"" value=""" & oRS("Title") & vbcrlf & """>"
' *** Index = 3
returnString = returnString & "<input type=hidden name=""" & oRS("id") & "label"" value=""" & oRS("Label") & vbcrlf & """>"
returnString = returnString & oRS("Name")
returnString = returnString & "</DIV>"
oRS.MoveNext
Loop
End If
oRS.Close
Set oRS = Nothing
oConn.Close
Set oConn = Nothing
returnString = returnString & "<div name=""moveForward"" style=""background-color: transparent; border: Black; width: 164; height: 32; background-image: url(images/linkbutton.gif);color:white; text-align: center; vertical-align: baseline; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-style: normal; font-size: xx-small; padding-top: 8;"" onClick=""moveForward();"">Next</div>"
loadLinks = returnString
end function
%>
<script language="JavaScript">
function setComment(oLink){
var sString;
sString = oLink(2).value ;
sString = sString + oLink(3).value;
sString = sString + oLink(0).value;
document.all["content"].innerText = sString;
}
function unsetComment(oLink){
document.all["content"].innerText = "";
}
function openLink(oLink){
window.open(oLink(1).value, '_blank');
}
function moveForward(){
alert('Session count = ' + <%=Session("Count")%> + ' Session nbr = ' + <%=Session("nbr") + 10%>);
if (<%=Session("Count")%> > <%=Session("nbr") + 10%> ) {
<%Session("nbr") = Session("nbr") + 10%>;
reloadPage(<%=Session("nbr")%>);
}
}
function moveBack(){
if (<%=Session("nbr")%> >= 11) {
<%Session("nbr") = Session("nbr") - 10 %>;
reloadPage(<%=Session("nbr")%>);
}
}
function reloadPage(iNbr){
location.href = 'loadpage.asp?table=<%=session("tablename")%>&filter=<%=Session("filter")%>&nbr=' + iNbr;
}
</script>
</head>
<BODY background="images/content_bg.jpg" bgcolor="#000000">
<input type="hidden" name="nbrs" id="nbrs" value="<%=Session("Count")%>">
<!-- Database selection block -->
<div style="left: 20; top: 5; position: absolute; width:350; height:395; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal; color: White;">
<p id="db"><% response.write("Selected database: " & session("tablename") & " " & Session("nbr")) %></p>
</div>
<!-- End of database selection block -->
<!-- Content block -->
<div style="left: 20; top: 20; position: absolute; width:350; height:395; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal; color: White;">
<p id="content"></p>
</div>
<!-- End of content block -->
<!-- Link control block -->
<div id="linkcontrol" style="width:165; height:395; left: 420; top: 15; position: absolute;">
<%
if Session("tablename") <> "tblParty" and Session("tablename") <> "tblWallpapers" then
response.write(loadLinks(session("tablename")))
else
response.redirect("loadpageimg.asp?table=" & session("tablename") & "&filter=" & Session("filter"))
end if
%>
</div>
<!-- End of link control block -->
</BODY>
</HTML>
Could somebody help or explain this behaviour? 
|