469,913 Members | 2,043 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,913 developers. It's quick & easy.

ASP Session variable problem ...

PM
I'm trying to make a kind of search history containing the 3 last
searched words. So I'm using 3 Session Variables: Word1 / Word2 /
Word3.

In order to get this history working, I need to put the last searched
word in the following Variable.

Ex.:
Session("Word3") = Session("Word2")
Session("Word2") = Session("Word1")
Session("Word1") = Request.QueryString("WORDS")

That way, Word1 is equal to the last searched word, Word2 is equal to
the last value contained in Word1 and Word3 is equal to the last value
contained in Word2.

So, if I search those words in order: carot, orange, apple, rabbit; it
should end up like this:

Word1 = "carot"
Word2 = ""
Word3 = ""

=========

Word1 = "orange"
Word2 = "carot"
Word3 = ""

=========

Word1 = "apple"
Word2 = "orange"
Word3 = "carot"

=========

Word1 = "rabbit"
Word2 = "apple"
Word3 = "orange"

=========

**************************
But instead of this I get:

Word1 = "carot"
Word2 = ""
Word3 = ""

=========

Word1 = "orange"
Word2 = "carot"
Word3 = "carot"

=========

Word1 = "apple"
Word2 = "orange"
Word3 = "orange"

=========

Word1 = "rabbit"
Word2 = "apple"
Word3 = "apple"

=========

I can't explain what is happening!?
Please, can somebody help me!
Thanks a lot!

** and sorry if my english isn't very good ...
Jul 19 '05 #1
3 3396
Is your "Ex." your actual code? That should work. Try this to see:
<%
Session("Word3") = Session("Word2")
Session("Word2") = Session("Word1")
Session("Word1") = Request.FORM("WORDS")
%>

<form method=post>
<input name="words">
<input type=submit>
</form>

<%
response.write "1: " & session("word1") & "<br>" & "2: " &
session("word2") & "<br>" & "3: " & session("word3")
%>

Ray at work

"PM" <pi***********@lanec.com> wrote in message
news:78**************************@posting.google.c om...
I'm trying to make a kind of search history containing the 3 last
searched words. So I'm using 3 Session Variables: Word1 / Word2 /
Word3.

In order to get this history working, I need to put the last searched
word in the following Variable.

Ex.:
Session("Word3") = Session("Word2")
Session("Word2") = Session("Word1")
Session("Word1") = Request.QueryString("WORDS")

That way, Word1 is equal to the last searched word, Word2 is equal to
the last value contained in Word1 and Word3 is equal to the last value
contained in Word2.

So, if I search those words in order: carot, orange, apple, rabbit; it
should end up like this:

Word1 = "carot"
Word2 = ""
Word3 = ""

=========

Word1 = "orange"
Word2 = "carot"
Word3 = ""

=========

Word1 = "apple"
Word2 = "orange"
Word3 = "carot"

=========

Word1 = "rabbit"
Word2 = "apple"
Word3 = "orange"

=========

**************************
But instead of this I get:

Word1 = "carot"
Word2 = ""
Word3 = ""

=========

Word1 = "orange"
Word2 = "carot"
Word3 = "carot"

=========

Word1 = "apple"
Word2 = "orange"
Word3 = "orange"

=========

Word1 = "rabbit"
Word2 = "apple"
Word3 = "apple"

=========

I can't explain what is happening!?
Please, can somebody help me!
Thanks a lot!

** and sorry if my english isn't very good ...

Jul 19 '05 #2
can you cut and paste your code so we can see it. It looks like word3 =
word1

John,

"PM" <pi***********@lanec.com> wrote in message
news:78**************************@posting.google.c om...
I'm trying to make a kind of search history containing the 3 last
searched words. So I'm using 3 Session Variables: Word1 / Word2 /
Word3.

In order to get this history working, I need to put the last searched
word in the following Variable.

Ex.:
Session("Word3") = Session("Word2")
Session("Word2") = Session("Word1")
Session("Word1") = Request.QueryString("WORDS")

That way, Word1 is equal to the last searched word, Word2 is equal to
the last value contained in Word1 and Word3 is equal to the last value
contained in Word2.

So, if I search those words in order: carot, orange, apple, rabbit; it
should end up like this:

Word1 = "carot"
Word2 = ""
Word3 = ""

=========

Word1 = "orange"
Word2 = "carot"
Word3 = ""

=========

Word1 = "apple"
Word2 = "orange"
Word3 = "carot"

=========

Word1 = "rabbit"
Word2 = "apple"
Word3 = "orange"

=========

**************************
But instead of this I get:

Word1 = "carot"
Word2 = ""
Word3 = ""

=========

Word1 = "orange"
Word2 = "carot"
Word3 = "carot"

=========

Word1 = "apple"
Word2 = "orange"
Word3 = "orange"

=========

Word1 = "rabbit"
Word2 = "apple"
Word3 = "apple"

=========

I can't explain what is happening!?
Please, can somebody help me!
Thanks a lot!

** and sorry if my english isn't very good ...

Jul 19 '05 #3
I i'm PM ...

I can't give you all my code here's what I can show you... anything else
does not effect thi section anyway...

Take note that "Word" is replaced by "mot", "mot" is french for "Word".
The QueryString "block" is only a flag that I use to say either I change
my session variables or not. The only time I change the those variables
is when I submit my form. Don't worry!, there is a form in my page, a
textfield named mots and a button used to submit it.

--- Befrore HTML ---
If (Not(Request.Cookies("mot1") Is Nothing)) And (Session("mot1") Is
Nothing) Then Session("mot1") = Request.Cookies("mot1").value
If (Not(Request.Cookies("mot2") Is Nothing)) And (Session("mot2") Is
Nothing) Then Session("mot2") = Request.Cookies("mot2").value
If (Not(Request.Cookies("mot3") Is Nothing)) And (Session("mot3") Is
Nothing) Then Session("mot3") = Request.Cookies("mot3").value

If Request.QueryString("block") <> "1" Then
If Trim(Request.QueryString("mots")) <> "" Then
Session("mot3") = Session("mot2")
Session("mot2") = Session("mot1")
Session("mot1") = Request.QueryString("mots")
End If
End If

--- IN HTML ---
<TABLE width="200" cellspacing="0" cellpadding="0" border="0"
bgcolor="<%=CLR_PNL_ROW1%>" style="border-left:1px solid
<%=CLR_PNL_END%>;border-bottom:1px solid <%=CLR_PNL_END%>;padding:4px">
<TR>
<TD class="main_texte"><img src="image/icon/icn_recherche.gif"
align="absmiddle" border="0">&nbsp;<b>Recherche</b></TD>
</TR>
<TR>
<TD>&nbsp;<asp:textbox class="inpbiblio" style="width:120px"
id="mots" RunAt="Server"/>&nbsp;<asp:button class="button"
ID="rechercher" Text="OK" OnClick="recherche_click"
RunAt="server"/></TD>
</TR>
<% If (Session("mot1") <> "") Then
Response.Cookies("mot1").value = Session("mot1")
Response.Cookies("mot1").expires = datetime.Now.AddDays(365)
%>
<TR>
<TD class="main_texte">&nbsp;<%=IMG_PNL_FLECHE%>&nbsp; <A
href="index.aspx?page=8&module=1&block=1&mots=<%=S ession("mot1")%>"><%=S
ession("mot1")%></A></TD>
</TR>
<% End If %>
<% If (Session("mot2") <> "") Then
Response.Cookies("mot2").value = Session("mot2")
Response.Cookies("mot2").expires = datetime.Now.AddDays(365)
%>
<TR>
<TD class="main_texte">&nbsp;<%=IMG_PNL_FLECHE%>&nbsp; <A
href="index.aspx?page=8&module=1&block=1&mots=<%=S ession("mot2")%>"><%=S
ession("mot2")%></A></TD>
</TR>
<% End If %>
<% If (Session("mot3") <> "") Then
Response.Cookies("mot3").value = Session("mot3")
Response.Cookies("mot3").expires = datetime.Now.AddDays(365)
%>
<TR>
<TD class="main_texte">&nbsp;<%=IMG_PNL_FLECHE%>&nbsp; <A
href="index.aspx?page=8&module=1&block=1&mots=<%=S ession("mot3")%>"><%=S
ession("mot3")%></A></TD>
</TR>
<TR>
<TD><img src="image/trans.gif" width="20" height="1"></TD>
</TR>
<% End If %>
</TABLE>

************************************************

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by William LaMartin | last post: by
9 posts views Thread by Greg Linwood | last post: by
4 posts views Thread by T Ralya | last post: by
3 posts views Thread by Alan Wang | last post: by
17 posts views Thread by Control Freq | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.