473,395 Members | 1,379 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,395 software developers and data experts.

session variable issue?

I have a function that is called when the user clicks the submit button,
during this function i also set a varaible to "Y" due to that this function
does a post back to the page then redirects. When I look for the session
variable in the page.isPostBack section it equals nothing, it appears that
the variable is not being passed to the post back section correctly. I have
this due to I only want this function to run if the user has something
selected in the grid.

code:
if checkbox.checked.tostring() = true then
dim cars as string = session("selection")
cars = "Y"
end if

in the post back
if page.isPostback
if session("selection") = "Y" then 'this equals nothing I debugged it and
its getting set in the function but being passed as NOTHING
run Function
end if
end if

Nov 18 '05 #1
6 1505
You are never assigning Session("Selection") to anything.

You are setting the string "cars" to 'Y', but since never assign the Session
it will not work the way you want. I can give a more detailed explaination
if you need one, but for now reverse your code like so:

'do not call .ToString() on this, just use the bool value checkd
if checkbox.checked = true then
dim cars as string
cars = "Y"
Session("selection") = cars
end if

Then you code on the next page will work as you are hoping for it to work.

bill

"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:3C**********************************@microsof t.com...
I have a function that is called when the user clicks the submit button,
during this function i also set a varaible to "Y" due to that this function does a post back to the page then redirects. When I look for the session
variable in the page.isPostBack section it equals nothing, it appears that the variable is not being passed to the post back section correctly. I have this due to I only want this function to run if the user has something
selected in the grid.

code:
if checkbox.checked.tostring() = true then
dim cars as string = session("selection")
cars = "Y"
end if

in the post back
if page.isPostback
if session("selection") = "Y" then 'this equals nothing I debugged it and its getting set in the function but being passed as NOTHING
run Function
end if
end if

Nov 18 '05 #2
I made the change you requested but i'm still having the same issue?

the session varaible is coming back blank

on the page where i'm setting the variable.
sub page_load
if page.ispostback then
if session("selection") = "Y" then 'this is sitll coming back as
nothing
response.write("You selected the following" & " " & cars)
end if
end if

im the button click routine
if CurrentCheckBox.Checked = True Then
Dim cars As String
selectedCars= "Y"
Session("selection") = selectedCars
End If

"William F. Robertson, Jr." wrote:
You are never assigning Session("Selection") to anything.

You are setting the string "cars" to 'Y', but since never assign the Session
it will not work the way you want. I can give a more detailed explaination
if you need one, but for now reverse your code like so:

'do not call .ToString() on this, just use the bool value checkd
if checkbox.checked = true then
dim cars as string
cars = "Y"
Session("selection") = cars
end if

Then you code on the next page will work as you are hoping for it to work.

bill

"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:3C**********************************@microsof t.com...
I have a function that is called when the user clicks the submit button,
during this function i also set a varaible to "Y" due to that this

function
does a post back to the page then redirects. When I look for the session
variable in the page.isPostBack section it equals nothing, it appears

that
the variable is not being passed to the post back section correctly. I

have
this due to I only want this function to run if the user has something
selected in the grid.

code:
if checkbox.checked.tostring() = true then
dim cars as string = session("selection")
cars = "Y"
end if

in the post back
if page.isPostback
if session("selection") = "Y" then 'this equals nothing I debugged it

and
its getting set in the function but being passed as NOTHING
run Function
end if
end if


Nov 18 '05 #3
Mike,

Are these code snippets on the same page? If so, then it will not work this
way. The Button click event is fired after Page_Load. So the session will
be Nothing as it has not been set yet. Typically you would show action is
response to a Button Click event, or you can just check the CheckBox
directly in page load, depending on what else you have going during your
page execution.

If the code is on two different pages, how are you transfering the user to
the other page. Response.Redirect, Server.Transfer, Execute?

bill

"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:29**********************************@microsof t.com...
I made the change you requested but i'm still having the same issue?

the session varaible is coming back blank

on the page where i'm setting the variable.
sub page_load
if page.ispostback then
if session("selection") = "Y" then 'this is sitll coming back as
nothing
response.write("You selected the following" & " " & cars)
end if
end if

im the button click routine
if CurrentCheckBox.Checked = True Then
Dim cars As String
selectedCars= "Y"
Session("selection") = selectedCars
End If

"William F. Robertson, Jr." wrote:
You are never assigning Session("Selection") to anything.

You are setting the string "cars" to 'Y', but since never assign the Session it will not work the way you want. I can give a more detailed explaination if you need one, but for now reverse your code like so:

'do not call .ToString() on this, just use the bool value checkd
if checkbox.checked = true then
dim cars as string
cars = "Y"
Session("selection") = cars
end if

Then you code on the next page will work as you are hoping for it to work.
bill

"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:3C**********************************@microsof t.com...
I have a function that is called when the user clicks the submit button, during this function i also set a varaible to "Y" due to that this

function
does a post back to the page then redirects. When I look for the session variable in the page.isPostBack section it equals nothing, it appears

that
the variable is not being passed to the post back section correctly. I

have
this due to I only want this function to run if the user has something
selected in the grid.

code:
if checkbox.checked.tostring() = true then
dim cars as string = session("selection")
cars = "Y"
end if

in the post back
if page.isPostback
if session("selection") = "Y" then 'this equals nothing I debugged
it and
its getting set in the function but being passed as NOTHING
run Function
end if
end if


Nov 18 '05 #4
they are on the same page for the reason being that I need to post back to
myself to get the users selection from the datalist, then pass only the items
selected to the detail page via a querystring. ( in which i'm also have an
issue with in .NET with this particular one.)

here is the button code snippet
For I = 0 To datalist.Items.Count - 1
checkBox= dlScores.Items(I).FindControl("chkCars")
carMake= dlScores.Items(I).FindControl("carmake")
cbValue = cbValue & checkbox.Checked.ToString()
If checkbox.Checked.ToString = True Then
carMake= carMake & carmake.Text.ToString() & "|"
End If
Next
response.redirect("cardetails.aspx?car=" & carMake)

this is the function that loops thru the datalist and gets me all the cars
selected then pass only them to the detail page.

Is there an easier way to do this? I only want this to fire when the button
is clicked by the user. Also with the querystring if i have the string
seperated with | it will not work, even if i split the string. though it will
work if i remove the | and only select one car in the datalist

"William F. Robertson, Jr." wrote:
Mike,

Are these code snippets on the same page? If so, then it will not work this
way. The Button click event is fired after Page_Load. So the session will
be Nothing as it has not been set yet. Typically you would show action is
response to a Button Click event, or you can just check the CheckBox
directly in page load, depending on what else you have going during your
page execution.

If the code is on two different pages, how are you transfering the user to
the other page. Response.Redirect, Server.Transfer, Execute?

bill

"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:29**********************************@microsof t.com...
I made the change you requested but i'm still having the same issue?

the session varaible is coming back blank

on the page where i'm setting the variable.
sub page_load
if page.ispostback then
if session("selection") = "Y" then 'this is sitll coming back as
nothing
response.write("You selected the following" & " " & cars)
end if
end if

im the button click routine
if CurrentCheckBox.Checked = True Then
Dim cars As String
selectedCars= "Y"
Session("selection") = selectedCars
End If

"William F. Robertson, Jr." wrote:
You are never assigning Session("Selection") to anything.

You are setting the string "cars" to 'Y', but since never assign the Session it will not work the way you want. I can give a more detailed explaination if you need one, but for now reverse your code like so:

'do not call .ToString() on this, just use the bool value checkd
if checkbox.checked = true then
dim cars as string
cars = "Y"
Session("selection") = cars
end if

Then you code on the next page will work as you are hoping for it to work.
bill

"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:3C**********************************@microsof t.com...
> I have a function that is called when the user clicks the submit button, > during this function i also set a varaible to "Y" due to that this
function
> does a post back to the page then redirects. When I look for the session > variable in the page.isPostBack section it equals nothing, it appears
that
> the variable is not being passed to the post back section correctly. I
have
> this due to I only want this function to run if the user has something
> selected in the grid.
>
> code:
> if checkbox.checked.tostring() = true then
> dim cars as string = session("selection")
> cars = "Y"
> end if
>
> in the post back
> if page.isPostback
> if session("selection") = "Y" then 'this equals nothing I debugged it and
> its getting set in the function but being passed as NOTHING
> run Function
> end if
> end if
>
>
>


Nov 18 '05 #5
I am guessing you did not set Option Explicit On on the top of of your code.
Without strongly typed variable definitions, and I not sure what type your
variables are.

is cbValue a checkbox or a bool?
what exactly does this line do? or rather, what should it do.
carMake= carMake & carmake.Text.ToString() & "|"

is carMake a string, or a text box.

Here is a link for the option explicit on MS site. I would HIGHLY
recommend, as would most posters on this newgroup, setting this.
http://msdn.microsoft.com/library/de...onExplicit.asp

Try using Server.UrlEncode, the pipe character might have some special
meaning through a querystring. ie

Response.Redirect( "cardetails.aspx?car=" + Server.UrlEncode( carMake ) )

bill
"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:37**********************************@microsof t.com...
they are on the same page for the reason being that I need to post back to
myself to get the users selection from the datalist, then pass only the items selected to the detail page via a querystring. ( in which i'm also have an
issue with in .NET with this particular one.)

here is the button code snippet
For I = 0 To datalist.Items.Count - 1
checkBox= dlScores.Items(I).FindControl("chkCars")
carMake= dlScores.Items(I).FindControl("carmake")
cbValue = cbValue & checkbox.Checked.ToString()
If checkbox.Checked.ToString = True Then
carMake= carMake & carmake.Text.ToString() & "|"
End If
Next
response.redirect("cardetails.aspx?car=" & carMake)

this is the function that loops thru the datalist and gets me all the cars
selected then pass only them to the detail page.

Is there an easier way to do this? I only want this to fire when the button is clicked by the user. Also with the querystring if i have the string
seperated with | it will not work, even if i split the string. though it will work if i remove the | and only select one car in the datalist

"William F. Robertson, Jr." wrote:
Mike,

Are these code snippets on the same page? If so, then it will not work this way. The Button click event is fired after Page_Load. So the session will be Nothing as it has not been set yet. Typically you would show action is response to a Button Click event, or you can just check the CheckBox
directly in page load, depending on what else you have going during your
page execution.

If the code is on two different pages, how are you transfering the user to the other page. Response.Redirect, Server.Transfer, Execute?

bill

"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:29**********************************@microsof t.com...
I made the change you requested but i'm still having the same issue?

the session varaible is coming back blank

on the page where i'm setting the variable.
sub page_load
if page.ispostback then
if session("selection") = "Y" then 'this is sitll coming back as nothing
response.write("You selected the following" & " " & cars)
end if
end if

im the button click routine
if CurrentCheckBox.Checked = True Then
Dim cars As String
selectedCars= "Y"
Session("selection") = selectedCars
End If

"William F. Robertson, Jr." wrote:

> You are never assigning Session("Selection") to anything.
>
> You are setting the string "cars" to 'Y', but since never assign the

Session
> it will not work the way you want. I can give a more detailed

explaination
> if you need one, but for now reverse your code like so:
>
> 'do not call .ToString() on this, just use the bool value checkd
> if checkbox.checked = true then
> dim cars as string
> cars = "Y"
> Session("selection") = cars
> end if
>
> Then you code on the next page will work as you are hoping for it to

work.
>
> bill
>
> "Mike" <Mi**@discussions.microsoft.com> wrote in message
> news:3C**********************************@microsof t.com...
> > I have a function that is called when the user clicks the submit

button,
> > during this function i also set a varaible to "Y" due to that this
> function
> > does a post back to the page then redirects. When I look for the

session
> > variable in the page.isPostBack section it equals nothing, it appears > that
> > the variable is not being passed to the post back section correctly. I > have
> > this due to I only want this function to run if the user has something > > selected in the grid.
> >
> > code:
> > if checkbox.checked.tostring() = true then
> > dim cars as string = session("selection")
> > cars = "Y"
> > end if
> >
> > in the post back
> > if page.isPostback
> > if session("selection") = "Y" then 'this equals nothing I
debugged it
> and
> > its getting set in the function but being passed as NOTHING
> > run Function
> > end if
> > end if
> >
> >
> >
>
>
>


Nov 18 '05 #6
Just something I noticed Mike. You are doing a redirect, but then you
handling code in inside a "ispostback" block. If you do a redirect, even if
it's to the same page you are on, then ispostback is false.

If I misunderstood you then I apologize.

Paul Ross
Hebco, Inc.
"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:37**********************************@microsof t.com...
they are on the same page for the reason being that I need to post back to
myself to get the users selection from the datalist, then pass only the
items
selected to the detail page via a querystring. ( in which i'm also have an
issue with in .NET with this particular one.)

here is the button code snippet
For I = 0 To datalist.Items.Count - 1
checkBox= dlScores.Items(I).FindControl("chkCars")
carMake= dlScores.Items(I).FindControl("carmake")
cbValue = cbValue & checkbox.Checked.ToString()
If checkbox.Checked.ToString = True Then
carMake= carMake & carmake.Text.ToString() & "|"
End If
Next
response.redirect("cardetails.aspx?car=" & carMake)

this is the function that loops thru the datalist and gets me all the cars
selected then pass only them to the detail page.

Is there an easier way to do this? I only want this to fire when the
button
is clicked by the user. Also with the querystring if i have the string
seperated with | it will not work, even if i split the string. though it
will
work if i remove the | and only select one car in the datalist

"William F. Robertson, Jr." wrote:
Mike,

Are these code snippets on the same page? If so, then it will not work
this
way. The Button click event is fired after Page_Load. So the session
will
be Nothing as it has not been set yet. Typically you would show action
is
response to a Button Click event, or you can just check the CheckBox
directly in page load, depending on what else you have going during your
page execution.

If the code is on two different pages, how are you transfering the user
to
the other page. Response.Redirect, Server.Transfer, Execute?

bill

"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:29**********************************@microsof t.com...
> I made the change you requested but i'm still having the same issue?
>
> the session varaible is coming back blank
>
> on the page where i'm setting the variable.
> sub page_load
> if page.ispostback then
> if session("selection") = "Y" then 'this is sitll coming back
> as
> nothing
> response.write("You selected the following" & " " & cars)
> end if
> end if
>
> im the button click routine
> if CurrentCheckBox.Checked = True Then
> Dim cars As String
> selectedCars= "Y"
> Session("selection") = selectedCars
> End If
>
>
>
> "William F. Robertson, Jr." wrote:
>
> > You are never assigning Session("Selection") to anything.
> >
> > You are setting the string "cars" to 'Y', but since never assign the

Session
> > it will not work the way you want. I can give a more detailed

explaination
> > if you need one, but for now reverse your code like so:
> >
> > 'do not call .ToString() on this, just use the bool value checkd
> > if checkbox.checked = true then
> > dim cars as string
> > cars = "Y"
> > Session("selection") = cars
> > end if
> >
> > Then you code on the next page will work as you are hoping for it to

work.
> >
> > bill
> >
> > "Mike" <Mi**@discussions.microsoft.com> wrote in message
> > news:3C**********************************@microsof t.com...
> > > I have a function that is called when the user clicks the submit

button,
> > > during this function i also set a varaible to "Y" due to that this
> > function
> > > does a post back to the page then redirects. When I look for the

session
> > > variable in the page.isPostBack section it equals nothing, it
> > > appears
> > that
> > > the variable is not being passed to the post back section
> > > correctly. I
> > have
> > > this due to I only want this function to run if the user has
> > > something
> > > selected in the grid.
> > >
> > > code:
> > > if checkbox.checked.tostring() = true then
> > > dim cars as string = session("selection")
> > > cars = "Y"
> > > end if
> > >
> > > in the post back
> > > if page.isPostback
> > > if session("selection") = "Y" then 'this equals nothing I
> > > debugged

it
> > and
> > > its getting set in the function but being passed as NOTHING
> > > run Function
> > > end if
> > > end if
> > >
> > >
> > >
> >
> >
> >


Nov 18 '05 #7

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

Similar topics

3
by: JP SIngh | last post by:
Hi All We have an ASP application which tracks holidays for our employees. When the user logs in we store thier username in a session variable and use that variable when displaying and adding...
2
by: Nate Spillson | last post by:
I have an asp.net web application that uses session variables to store user information (username, security areas, configuration data). When the user logs into the system I store all of this...
9
by: Greg Linwood | last post by:
I'm having difficulty understanding Session state in ASP.Net. It's almost embarrassing asking this as I've been using ASP since it was first released & it really shouldn't be this hard to use -...
5
by: ASP.Confused | last post by:
As you can tell from my previous posts on this issue...I'm really confused :-/ I have a few ASP.NET web applications on my web host's "https" server. Our web host has a single "bin" folder for...
13
by: Simon Matthews | last post by:
I am having issues with the right way to architecture the following (using c# asp.net):- The question I have is how best pass the collected data from one web page for use in another. The...
4
by: T Ralya | last post by:
I am told that ASP.NET controls the session ID and session variables, but that does not fit my symptoms. I am posting here as directed. I'm hoping that someone can at least recommend something to...
4
by: Sarah Marriott | last post by:
Our website contains session variables that are used to validate if a user is logged in etc. We have found that these variables are randomly lost while navigating the website. We set up some...
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...
5
by: Sam | last post by:
Hi All, I have a very weird issue with my session variable and I'm hoping that someone can help me out. The issue is my session variable dissappears after a request is redirected to a new page....
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
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...
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...
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
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.