ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 26th, 2003, 06:52 AM
dragonsteve dragonsteve is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: Belgium, Poperinge
Posts: 12 dragonsteve User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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" oConn23
        
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?

Reply With Quote
  #2  
Old April 28th, 2003, 09:49 PM
numbernine numbernine is offline
Up To His Eyes In Ads
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Chicago
Posts: 160 numbernine User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 25 sec
Reputation Power: 6
I'm not sure I completely follow but it looks like you may be mixing client-side and server-side scripting. Everything in the <% %> blocks will be run long before the page ever hits the browser to run the javascript. By the time the javascript if statements are evaluated, the ASP code has already been completely run. So you're going to add 10 to Session("nbr") and subtract 10 from Session("nbr") every time the page is loaded...right?

Reply With Quote
  #3  
Old May 2nd, 2003, 06:43 AM
dragonsteve dragonsteve is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: Belgium, Poperinge
Posts: 12 dragonsteve User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thx numbernine for that pointing this out to me.
I have already changed that.

That is probably the problem I'm having.


Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingASP Development > Session variable strange behaviour


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway