471,319 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 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 4312
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Tyros | last post: by
6 posts views Thread by JJ_377 | last post: by
3 posts views Thread by Alan Wang | last post: by
26 posts views Thread by BillE | last post: by
6 posts views Thread by =?Utf-8?B?R2Vv?= | last post: by

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.