HOWTO: Persisting Values Without SessionsID: Q175167
|
When developing Web sites with HTML forms you may need to keep track of
information entered by a user for use at a later time. This process is
called persisting values.
Active Server Pages (ASP) provides Session variables to facilitate this;
however, these require the use of session IDs. This article describes
methods of storing form values without using session cookies.
Three methods are commonly used to persist values when developing in HTML:
<%@ LANGUAGE="VBSCRIPT" %>
<!-- This is FORM1.HTM -->
<HTML>
<HEAD><TITLE>FORM1.HTM</TITLE></HEAD>
<BODY>
<Form Action=Form2.asp Method=Post>
<Input Type=Text Value="Page1 Value" Name="Value1"><P>
<Input Type=Submit Name=btnSubmit>
</Form>
</BODY>
</HTML>
<!-- This is FORM2.ASP -->
<%@ LANGUAGE="VBSCRIPT" %>
<%
Response.Cookies("Value1") = Request("Value1")
' If you wish to have the value persisted beyond the current visit,
' you must also assign an expiration date as follows:
Response.Cookies("Value1").Expires = "July 31, 1998"
%>
<HTML>
<HEAD><TITLE>FORM2.ASP</TITLE></HEAD>
<BODY>
<Form Action=Form3.asp Method=Post>
<Input Type=Text Value="Page2 Value" Name="Value2"><P>
<Input Type=Submit Name=btnSubmit>
</Form>
</BODY>
</HTML>
<!-- This is FORM3.ASP -->
<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<HEAD><TITLE>FORM3.ASP</TITLE></HEAD>
<BODY>
Value 1 = <%= Request("Value1") %><BR>
Value 2 = <%= Request("Value2") %><BR>
</BODY>
</HTML>
<!-- This is FORM1.HTM -->
<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<HEAD><TITLE>FORM1.HTM</TITLE></HEAD>
<BODY>
<Form Action=Form2.asp Method=Post>
<Input Type=Text Value="Page1 Value" Name="Value1"><P>
<Input Type=Submit Name=btnSubmit>
</Form>
</BODY>
</HTML>
<!-- This is FORM2.ASP -->
<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<HEAD><TITLE>FORM2.ASP</TITLE></HEAD>
<BODY>
<Form Action="Form3.asp?value1=<%=
Server.URLEncode(Request("Value1"))
%>" Method=Post>
<Input Type=Text Value="Page2 Value" Name="Value2"><P>
<Input Type=Submit Name=btnSubmit>
</Form>
</BODY>
</HTML>
<!-- This is FORM3.ASP -->
<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<HEAD><TITLE>FORM3.ASP</TITLE></HEAD>
<BODY>
Value 1 = <%= Request("Value1") %><BR>
Value 2 = <%= Request("Value2") %><BR>
</BODY>
</HTML>
<!-- This is FORM1.HTM -->
<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<HEAD><TITLE>FORM1.HTM</TITLE></HEAD>
<BODY>
<Form Action=Form2.asp Method=Post>
<Input Type=Text Value="Page1 Value" Name="Value1"><P>
<Input Type=Submit Name=btnSubmit>
</Form>
</BODY>
</HTML>
<!-- This is FORM2.ASP -->
<%@ LANGUAGE="VBSCRIPT" %>
<% Response.Cookies("Value1") = Request("Value1") %>
<HTML>
<HEAD><TITLE>FORM2.ASP</TITLE></HEAD>
<BODY>
<Form Action=Form3.asp Method=Post>
<Input Type=Text Value="Page2 Value" Name="Value2"><P>
<Input Type=Submit Name=btnSubmit>
</Form>
</BODY>
</HTML>
<!-- This is FORM3.ASP -->
<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<HEAD><TITLE>FORM3.ASP</TITLE></HEAD>
<BODY>
Value 1 = <%= Request.Cookies("Value1") %><BR>
Value 2 = <%= Request("Value2") %><BR>
</BODY>
</HTML>
For the latest Knowledge Base artices and other support information on
Visual InterDev and Active Server Pages, see the following page on the
Microsoft Technical Support site:
http://support.microsoft.com/support/vinterdev/
Additional query words:
Keywords : kbASP kbASPObj kbScript kbVBScript kbVisID100 kbGrpASP
Version : WINDOWS:97,97sp1,97sp2,97sp3; winnt:
Platform : WINDOWS winnt
Issue type : kbhowto
Last Reviewed: May 27, 1999