By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,306 Members | 1,657 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,306 IT Pros & Developers. It's quick & easy.

Dummy question: How to retrieve Session state Variable from another Page?

P: n/a
Hi, Gurus,
I have two web forms frm1 and frm2. In frm1, I wrote session("StudentID")=
textbox1.text in a button click event. And then, Response.redirect("...frm2")
In frm2, Page_load event, I tried both response.write session("StudentID") and
textbox2.text=session("studentID"), none of them showing me what I got from frm1.
I don't know why??
My web.config reads:
.....................

<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;user id=sa;password="
cookieless="false"
timeout="20"
/>
........................

Please help!!!
Thank you
Nov 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Carl Prothman [MVP]" <ca****@spamcop.net> wrote

TextBox1.Text = DirectCast(Session("StudentID"))


Correction :
TextBox1.Text = DirectCast(Session("StudentID"), String)

Nov 17 '05 #2

P: n/a
"Carl Prothman [MVP]" <ca****@spamcop.net> wrote in message news:<uT**************@TK2MSFTNGP09.phx.gbl>...
"Carl Prothman [MVP]" <ca****@spamcop.net> wrote

TextBox1.Text = DirectCast(Session("StudentID"))


Correction :
TextBox1.Text = DirectCast(Session("StudentID"), String)


Carl,
Thank you very much for you reply.
But I tried, still doesn't work.
Here is what I did:

Page1: button1 click event.
Session("StudentID")="12345"
Response.write session("Student")

It even works withoout DIRECTCAST on the same page.

IF I do:
Page1:
Session("StudentID")="12345"
Response.Redirect("http://Testweb/frmPage2.aspx")

Page2:
Page_load-----response.write(directcast(session("StudentID"),str ing))
or textbox1.text=directcast(session("StudentID"),stri ng))
(----textbox1 is on page2----)
No error pops up but it does not show the 12345 either in the textbox
or on the left top side of the screen(I suppose this place is for
response.write)

Is this because thw way I used response.redirect?

Thank you
Nov 17 '05 #3

P: n/a
Carl, After I post last message, I tested it from a test machine by
opening the link and the page, it works!!!!!
Do you have any idea why I can see it working in .NET Development even
though I re-built the solution?

Thank you,
Tuxedo

"Carl Prothman [MVP]" <ca****@spamcop.net> wrote in message news:<uT**************@TK2MSFTNGP09.phx.gbl>...
"Carl Prothman [MVP]" <ca****@spamcop.net> wrote

TextBox1.Text = DirectCast(Session("StudentID"))


Correction :
TextBox1.Text = DirectCast(Session("StudentID"), String)

Nov 17 '05 #4

P: n/a
"tuxedo" <tu*********@yahoo.com> wrote
Carl, After I post last message, I tested it from a test machine by
opening the link and the page, it works!!!!!

Tuxedo,
Cool. I'm glad you got it working on at least one machine... ;-)

Do you have any idea why I can see it working in .NET Development even
though I re-built the solution?


ASP.NET Session requires that you have an IIS Application (not just a virtual directory)
with a global.asax file in the root. Plus your Web browser must be cookie enabled
to accept a Session cookie, otherwise you'll need to use Session-less cookies via
the web.config's "sessionState" tag.

Anytime you save changes to global.asax., web.config, machine.config,
you'll restart your IIS Application. Make sure your anti-virus software
is not "touching" these files.

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP
http://www.able-consulting.com


Nov 17 '05 #5

P: n/a
"tuxedo" <tu*********@yahoo.com> wrote
Carl, After I post last message, I tested it from a test machine by
opening the link and the page, it works!!!!!

Tuxedo,
Cool. I'm glad you got it working on at least one machine... ;-)

Do you have any idea why I can see it working in .NET Development even
though I re-built the solution?


ASP.NET Session requires that you have an IIS Application (not just a virtual directory)
with a global.asax file in the root. Plus your Web browser must be cookie enabled
to accept a Session cookie, otherwise you'll need to use Session-less cookies via
the web.config's "sessionState" tag.

Anytime you save changes to global.asax., web.config, machine.config,
you'll restart your IIS Application. Make sure your anti-virus software
is not "touching" these files.

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP
http://www.able-consulting.com


Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.