PRB: Session Variables Lost When ASP is Located in FramesetID: Q178037
|
Values of session variables defined in an Active Server Pages (ASP) page are empty when you attempt to access the values from other ASP pages within the frameset.
The following conditions cause this error to occur:
Active Server Pages maintains a session only when necessary (for example, if a session variable is created). To avoid this behavior you must establish a session before the frameset is processed. In most cases, the easiest way to do this is by changing the file which defines the frameset from an HTML file to an ASP file.
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Developer Studio">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Document Title</TITLE>
</HEAD>
<BODY>
<FRAMESET FRAMEBORDER=0 SCROLLING=YES ROWS="15%, 70%, *">
<FRAME NAME="Top" SCROLLING="NO" SRC="Top.asp">
<FRAME NAME="Middle" SCROLLING="AUTO" SRC="Middle.asp">
<FRAME NAME="Bottom" SCROLLING="NO" SRC="Bottom.asp">
</FRAMESET>
</BODY>
</HTML>
<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Document Title</TITLE>
</HEAD>
<BODY>
<% Response.Write( "Top.asp: " & Session.SessionID ) %>
<%'set a session variable I want to be global to all asp files in the
frameset session("GlobalVar")="Top"%>
</BODY>
</HTML>
<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Document Title</TITLE>
</HEAD>
<BODY>
<% Response.Write( "Middle.asp: " & Session.SessionID ) %>
<SCRIPT LANGUAGE="VBScript">
Sub CommandButton1_Click()
'display the global variable set in top.asp
msgbox "<%=session("GlobalVar")%>"
'if GlobalVar is blank, it means the variable is scoped to a
'different session.
end sub
</SCRIPT>
<OBJECT ID="CommandButton1" WIDTH=96 HEIGHT=32
CLASSID="CLSID:D7053240-CE69-11CD-A777-00DD01143C57">
<PARAM NAME="Caption" VALUE="display gvar">
<PARAM NAME="Size" VALUE="2540;846">
<PARAM NAME="FontCharSet" VALUE="0">
<PARAM NAME="FontPitchAndFamily" VALUE="2">
<PARAM NAME="ParagraphAlign" VALUE="3">
</OBJECT>
</BODY>
</HTML>
<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Document Title</TITLE>
</HEAD>
<BODY>
<% Response.Write( "Bottom.asp: " & Session.SessionID ) %>
<% Session("MyVar") = "Bottom" %>
</BODY>
</HTML>
<% Session("MyVar") = "Main" %>
Additional query words:
Keywords : kbASP kbASPObj kbScript kbVisID kbGrpASP
Version : winnt:
Platform : winnt
Issue type : kbprb
Last Reviewed: May 27, 1999