Wrox Programmer Forums
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Dreamweaver (all versions) section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 2nd, 2004, 07:06 AM
Registered User
 
Join Date: Oct 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Session State - Page 265

The code below does not work as stated in para 10 of page 265. When I click on the 'Tell Us Your Name' Button, my name appears and the form disappears. That is how it should be. However, when I refresh the browser my user name is no longer visible; I understand it should be? Also, when I link to another page in the menu and then return to the home page by selecting Home my username is not there; I understand it should be? Have I entered any code incorrectly or is the problem a function of cookies - Please note, I have checked and confirmed that both cookies and Session State are enabled!

Regards

Iain


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% If Trim(Request.Form("txtUserName")) <> "" Then
Session("UserName") = Trim(Request.Form("txtUserName"))
End If
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>GlobalSoccerEvents.com - Your Source for Soccer Events Around the Globe</title>

<style type="text/css">
<!--
td {
    font-family: Arial, Helvetica, sans-serif;
    color: #000000;
}
a {
    font-family: Arial, Helvetica, sans-serif;
    color: #009933;
}
-->
</style>
</head>

<body><table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><img src="Images/logo.gif" alt="logo" width="257" height="58"></td>
    <td><table border="0" align="right" cellpadding="0" cellspacing="0">
  <tr>
    <td><a href="home.asp" id="home">Home</a></td>
    <td> </td>
    <td><a href="events.asp" id="events">Events</a></td>
    <td> </td>
    <td><a href="mysite.asp" id="mysite">My Site</a></td>
  </tr>
</table>
</td>
  </tr>
</table>
<br>
<script language="JavaScript" type="text/javascript">
var sPageName = '<%=Request.ServerVariables("SCRIPT_NAME")%>';
sPageName = sPageName.substr(sPageName.lastIndexOf('/')
+ 1).toLowerCase();
sPageName = sPageName.substr(0, sPageName.lastIndexOf('.'));
if (document.getElementById(sPageName))
{
    document.getElementById(sPageName).style.fontWeigh t='Bold';
    document.getElementById(sPageName).style.fontSize= '14pt';
}
</script><table width="100%" border="0" cellspacing="5" cellpadding="0">
  <tr>
    <td><h2>Welcome to GlobalSoccerEvents.com</h2></td>
  </tr>
  <tr>
    <td>Your Source for Soccer Events Around the Globe.
    <br>

      <% If Session("UserName") = "" Then %>Please enter your name and hit the "Tell Us your Name" button <br><br>
<br><form action="home.asp" method="post" name="frmUserName"><input name="txtUserName" type="text"><input name="btnSubmit" type="submit" value="Tell Us Your Name"></form><% Else %>
      Welcome, <%=Session("Username") %>.
      <% End If %>
    </td>
  </tr>
  <tr>
    <td align="center"><br>
<br>
<br>
<br>
<br>
Having difficulties? Contact the Webmaster
    </td>
  </tr>
</table>
</body>
</html>
 
Old November 2nd, 2004, 05:08 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Iain,

Are you sure it's not related to Sessions or cookies? I just copied and pasted your code in my TheSoccerSite trial site, and everything worked as expected.
Maybe a firewall or other software is blocking your cookies.... Can you try a simple example? (If you want, I can provide sample code for that)

And wat's the name of the file you're trying this with? Are you posting back to home.asp??

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Downfall by Laurent Garnier (Track 11 from the album: Unreasonable Behaviour) What's This?
 
Old November 2nd, 2004, 06:40 PM
Registered User
 
Join Date: Oct 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar
The file name is home.asp and I am posting back to it. I have checked and Session and Cookies are enabled and I have tried turning off my Firewall but to no avail. I don't know how else to check if cookies are enabled so if yo have instructions/code to check then I would appreciate it.

regards

Iain

 
Old November 3rd, 2004, 04:07 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

To try this out, create two new pages called Page1.asp and Page2.asp.

In the <body> of Page1.asp add the following code:
Code:
<%
    Response.Cookies("Test") = "This is a test of a cookie"
    Session("Test") = "This is a test of a session variable"

    Response.Redirect("Page2.asp")
%>
Between the <body> tags of page two add this code:
Code:
<%

    Response.Write("Cookie has a value of " & Request.Cookies("Test") & "<br />")
    Response.Write("Session has a value of " & Session("Test") & "<br />")

%>
Load Page1.asp in your browser. It should redirect you to the second page, showing you the values of Cookie and the Session variable, respectively.

Let me know if this works so we can work on the main problem of the Home.asp page.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old November 3rd, 2004, 05:22 AM
Registered User
 
Join Date: Oct 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Imar

Thank you for this. As stated I have both sessions and cookies enabled. I am using Zone Alarm (ZA) Professional. In the Privacy tab of ZA I have Cookie Control turned off; ie Cookie control is disabled and all cookies are allowed. When I run your test program I get the following message

"Cookie has a value of
Session has a value of"

However when I close down ZA altogether and run the test program I get:

"Cookie has a value of This is a test of a cookie
Session has a value of This is a test of a session variable"

I take it the latter message is correct?

It would appear that my ZA Firewall is the problem. It would appear that turning off Cookie control in ZA is not sufficient; I have to close the program down altogether! Surely, this cannot be right?

Regards

Iain

 
Old November 3rd, 2004, 06:55 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I don't know much about ZA, but apparently it is blocking your cookies (Sessions in ASP work with a Cookie as well).

Maybe there is an option in ZA to allow session cookies? Or to add your development machine to the trusted site?

The latter message is indeed correct; with ZA turned off, I'm sure that Home.asp will work as well.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Session State Problem? caterpillar ASP.NET 1.0 and 1.1 Basics 8 August 17th, 2006 03:08 PM
tradeoff application vs session state vs page Redden ASP.NET 1.x and 2.0 Application Design 1 October 6th, 2005 12:44 AM
Session State|View State|Do I have other options? rockon ASP.NET 1.x and 2.0 Application Design 2 October 5th, 2005 07:10 PM
maintaining session state in C# grs General .NET 0 January 13th, 2005 03:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.