ASP Session variable problem ...

P

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 ...
 
R

Ray at

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
 
P

Pierre-Michel Morais-Godin

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=<%=Session("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=<%=Session("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=<%=Session("mot3")%>"><%=S
ession("mot3")%></A></TD>
</TR>
<TR>
<TD><img src="image/trans.gif" width="20" height="1"></TD>
</TR>
<% End If %>
</TABLE>

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,156
Latest member
KetoBurnSupplement
Top