473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Clearing Session Variables

Amy
I'm having a problem with clearing my session variables. I'm using
session variables to pass data from a web form to a pdf generator.
The problem comes in when a user goes back to the original page and
takes data out of the field - the session variable is persisting.

i tried the following, and it didn't work - I'm not sure where to go
from here. Any advice would be appreciated. The string being passed
is both the variable name and the name of the session variable.
public bool CheckIfEmpty (string test)
{
if (test == "")
{

Session.Remove(test);
return true;
}
else
{
return false;
}

}
Nov 30 '05 #1
4 4436
Amy,

You are only removing a variable if the string is empty. I would think
you want to move the call to Remove into the "false" part of the check.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Amy" <am*******@mccombs.utexas.edu> wrote in message
news:3c********************************@4ax.com...
I'm having a problem with clearing my session variables. I'm using
session variables to pass data from a web form to a pdf generator.
The problem comes in when a user goes back to the original page and
takes data out of the field - the session variable is persisting.

i tried the following, and it didn't work - I'm not sure where to go
from here. Any advice would be appreciated. The string being passed
is both the variable name and the name of the session variable.
public bool CheckIfEmpty (string test)
{
if (test == "")
{

Session.Remove(test);
return true;
}
else
{
return false;
}

}

Nov 30 '05 #2
Amy
I think I only *want* to remove the variable if the string is empty.
If I remove it
and it's not empty, then, the data I want to keep isn't getting
passed, right? Here's how the method is being used:

if (CheckIfEmpty(locAdd2) == false)
{
Session.Add("locAdd2", locAdd2);
}

so, the first time the user fills out the form, if they filled out
that form field, it gets added as a Session variable. If they come
back to the form and change the data, the data changes. But if they
come back and clear all the information out, the original data
persists.

(the method again, for reference):

public bool CheckIfEmpty (string test)
{
if (test == "")
{

Session.Remove(test);
return true;
}
else
{
return false;
}

On Wed, 30 Nov 2005 11:30:50 -0500, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.com> wrote:
Amy,

You are only removing a variable if the string is empty. I would think
you want to move the call to Remove into the "false" part of the check.

Hope this helps.

Nov 30 '05 #3
try: Session.Remove(Session.Keys(x))
"Amy" <am*******@mccombs.utexas.edu> schreef in bericht
news:3c********************************@4ax.com...
I'm having a problem with clearing my session variables. I'm using
session variables to pass data from a web form to a pdf generator.
The problem comes in when a user goes back to the original page and
takes data out of the field - the session variable is persisting.

i tried the following, and it didn't work - I'm not sure where to go
from here. Any advice would be appreciated. The string being passed
is both the variable name and the name of the session variable.
public bool CheckIfEmpty (string test)
{
if (test == "")
{

Session.Remove(test);
return true;
}
else
{
return false;
}

}

Nov 30 '05 #4
Amy

I never did get the Session.Remove to work in this method. The
solution I found is to use Session.Clear on the second page, after I
was done with all the Session variables. So when I go back to the
first page, I'm starting with a clean slate.

If anyone can tell me why the Session.Remove in the method below
didn't work, I'd love to know.

--Amy Jones

On Wed, 30 Nov 2005 10:39:26 -0600, Amy <am*******@mccombs.utexas.edu>
wrote:
I think I only *want* to remove the variable if the string is empty.
If I remove it
and it's not empty, then, the data I want to keep isn't getting
passed, right? Here's how the method is being used:

if (CheckIfEmpty(locAdd2) == false)
{
Session.Add("locAdd2", locAdd2);
}

so, the first time the user fills out the form, if they filled out
that form field, it gets added as a Session variable. If they come
back to the form and change the data, the data changes. But if they
come back and clear all the information out, the original data
persists.

(the method again, for reference):

public bool CheckIfEmpty (string test)
{
if (test == "")
{

Session.Remove(test);
return true;
}
else
{
return false;
}

On Wed, 30 Nov 2005 11:30:50 -0500, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.com> wrote:
Amy,

You are only removing a variable if the string is empty. I would think
you want to move the call to Remove into the "false" part of the check.

Hope this helps.

Dec 1 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Al Jones | last post by:
This is a repost form the vbscript newgroup - if this isn't the appropriate group would you point me toward one that is. Basically, I seem to be losing session data part way though preparing an...
1
by: Tyros | last post by:
I'm new to C# and I'm dynamically creating a table control that contains a text control inside one of the cells. I load the values of each text field with an SQL call. The form is simple and I'm...
6
by: JJ_377 | last post by:
In a "Save and Quit" button on my web app form (aspx), I have the following code that is supposed to clear a session variable (an user id) and redirect to a logon page: Session.Clear()...
0
by: PD | last post by:
I am trying to stream out a PDF file via the response object and when I execute the code it always brings up the first document that I pulled up.Even when I step through the code, I can see the new...
3
by: Alan Wang | last post by:
Hi there, Once my application gets complicated and complicated. I found it's really hard to keep track of Session value I am using in my asp.net application. I am just wondering if anyone have...
7
by: Kermit Piper | last post by:
Hello, How can you clear session variables when a reset button is pressed? I thought I might be able to do something like: <% If request.form("Reset") = "Reset" then Session("variable") =...
18
by: BillE | last post by:
When a user opens a new IE browser window using File-New-Window the integrity of an application which relies on session state is COMPLETELY undermined. Anyone who overlooks the fact that...
26
by: BillE | last post by:
Some ASP.NET applications use Session Variables extensively to maintain state. These should be re-written to use viewstate, hidden fields, querystring, etc. instead. This is because if a user...
6
by: =?Utf-8?B?R2Vv?= | last post by:
Hi, I use lots of sessions. I want to clear the unwanted sessions when I leave a page. I cant use ViewState as it will slow down the pages. Could some one help me on this?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.