473,383 Members | 1,843 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,383 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 4434
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?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.