Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics 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 21st, 2003, 11:23 AM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
Default Assigning Session Variables

If I have a session variable in an include file
Sesssion("User")
If I have 2 links set up like this

<a href="MainView.asp" target="_top"><%Session("User") = "guest" %>Click Here</a>

<a href="MainView.asp" target="_top"><%Session("User") = "Member" %>Member</a>

How do I set the variables to nothing when the user returns to this page, either by back button or by link, because the session is just holding what ever the last one I clicked on was. Unless I re open the browser. I tried this
<% Session("user") = "" %> But it dosen't work right, when I go back to the page and click on the link again it dosen't change the variable. Is there a better way to go about this, or am I just missing something. Thanks for your help :)

__________________
-----------------------------------------------------------
\"Don\'t follow someone who\'s not going anywhere\" John Mason
 
Old November 21st, 2003, 11:47 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You are misunderstanding how this code works...

Anything you have inside of <% %> tags in your asp page gets processed when the page is requested. The result is drawn out to the browser. What your code is saying is:

Set Session("User") = "guest"
Set Session("User") = "member" 'This overwrites the previous line.

This will not do what you are indending which is to set the session variable to a value when you click on a link. That can not be done. This code is always going to leave Session("user") = "member".

You would need to do something like this in your HTML:

<a href="MainView.asp?user=guest" target="_top">Click Here</a>
<a href="MainView.asp?user=member" target="_top">Member</a>

Then on MainView.asp, you have ASP script that reads that value and puts it in the session:

Session("user") = Request.QueryString("user")

At the beginning of the page in question you could then clear the session value:

Session("user") = ""

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old November 21st, 2003, 01:55 PM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you, I will give it a shot






Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning value to session object from repeater. aloktripathi.13 ASP.NET 2.0 Professional 1 November 16th, 2007 09:23 AM
Assigning values to variables in Stored Procedures AlanAtMars SQL Server 2000 3 May 4th, 2005 12:37 AM
Assigning Values to Variables shabboleth Beginning PHP 2 September 4th, 2003 07:17 AM





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