Session variables not pointing to Request.Form Values

I am trying to take the value a user inputs from a form and put it into a session variable.  The basic code (on Page1) is thus:

Session("first_name") = Request.Form("first_name")

If I reference the session variable on that same page (such as <%= Session("first_name") %>) it works fine.   However, when I go to a new page (Page2) it does not work anymore, the session variable just shows up blank.  If I go back to the first page and set the session variable equal to a simple string it works and will show up fine on both pages.  Like thus:

Session("first_name") = "first name"

I realized what was happening is that Session("first_name") is not being set to the contents of Request.Form("first_name") but is instead pointing to the actual Request.Form object.  If I include a <input type="hidden" name="first_name" value="some value here"> on Page2 then when I try to display Session("first_name") it displays "some value here" because it is now pointing to the Request.Form("first_name") on Page2 instead of on Page1.

Are session variables just pointers to the Request.Form variable?  Is there a way to set it to the actual content of the input field so I can pass it to the next page?

 

0
jfrank
5/28/2008 2:23:04 PM
asp.net.state-management 8807 articles. 0 followers. Follow

6 Replies
637 Views

Similar Articles

[PageSpeed] 16

If you're using TextBox, than instead of Request.Form use this:
Session("first_name") = TextBox1.Text

0
kipo
5/28/2008 2:34:27 PM

I don't think I'm using textBox.  I'm not familiar with it, but I would assume that I would have had to specifically declare it.

 Edit: If you're referring to <asp:Textbox> I am not using it.  The tags are simple HTML <input>

0
jfrank
5/28/2008 2:38:08 PM

Can you post your whole code (page and code-behind)?

0
kipo
5/28/2008 3:00:22 PM

Ok, there are three pages.  I'm sure this isn't done according to the standard development model, as I'm new to ASP.Net and just trying to get this working.

 Page 1 (input.aspx):

1    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
3 <script runat="server">
4
5 Sub SubmitBtn_Click(ByVal Sender As Object, ByVal E As EventArgs)
6 Server.Transfer("confirm.aspx", True)
7 End Sub
8
9 </script>
10
11 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
12
13 <head runat="server">
14
15 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
16 <title></title>
17
18 </head>
19 <body>
20
21 <form id="form1" runat="server">
22
23
24 <table>
25 <tr>
26 <td>First Name</td>
27 <td>
28 <input style="WIDTH: 250px; HEIGHT: 22px" size="44" name="first_name">
29 </td>
30 </tr>
31 <tr>
32 <td>Last Name</td>
33 <td>
34 <input style="WIDTH: 250px; HEIGHT: 22px" size="44" name="last_name">
35 </td>
36 </tr>
37 </table>
38
39 <asp:button text="Submit" OnClick="SubmitBtn_Click" runat="server" id="Button1" />
40
41 </form>
42 </body>
43 </html>
Page 2 (confirm.aspx):
1    
2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
3 <html>
4 <script runat="server">
5
6 Sub SubmitBtn_Click(ByVal Sender As Object, ByVal E As EventArgs)
7 Server.Transfer("submit.aspx", True)
8 End Sub
9
10 ' When the page loads
11
12 Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
13
14 Session("first_name") = Request.Form("first_name")
15 Session("last_name") = Request.Form("last_name")
16
17 Message.InnerHtml = "First Name: " & Session("first_name") & "<br/>Last Name:</td><td>" & Session("last_name")
18
19 End Sub
20
21 </script>
22
23 <head id="Head1" runat="server">
24
25
26 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
27 <title></title>
28 </head>
29
30 <body>
31
32 <form id="form1" runat="server">
33
34 Please Confirm these Details:
35
36 <div id="Message" runat="server" />
37
38 <asp:button text="Submit" OnClick="SubmitBtn_Click" runat="server" id="Button1" />
39
40 </form>
41 </body>
42 </html>
 Page 3 (submit.aspx):
1    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2 <html>
3
4 <head id="Head1" runat="server">
5
6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7 <title></title>
8 </head>
9 <body>
10
11 You have submitted these details:
12
13 <%= Session("first_name") & Session("last_name") %>
14
15 </body>
16 </html>
Everything works fine up to Page 3 (submit.aspx) where the Session variables at line 13 don't show up.  If I go back to Page 2 (confirm.aspx) and change lines 14 and 15 thus, then the session variables show up fine in Page 3 (submit.aspx) as whatever strings I defined them as:
14   				Session("first_name") = "first_name"
15 Session("last_name") = "last_name"
 Or, if I include this on Page 2 (confirm.aspx) inside the <form> tag:
1    <input type="hidden" name="first_name" value="My First Name Value"/>
2 <input type="hidden" name="last_name" value="My Last Name Value"/>
Then on Page 3 (submit.aspx) the page returns the values I put in those <input> tags as the values for the Session variables.  I presume that on Page 2 the session variables have somehow been set to point to the Request.Form objects rather than to the contents of the Request.Form objects coming from page 1.
  
  
0
jfrank
5/28/2008 3:23:55 PM

You should use TextBox control instead input fields, so replace this:

<input style="WIDTH: 250px; HEIGHT: 22px" size="44" name="first_name">
with this:
<asp:TextBox ID="first_name" runat="server" />
and change your code in input.aspx into this:
Sub SubmitBtn_Click(ByVal Sender As Object, ByVal E As EventArgs)
 Session("first_name") = first_name.Text       
 Server.Transfer("confirm.aspx", True)       
End Sub

0
kipo
5/28/2008 4:49:13 PM

 Incredible.  Thanks for the help!  I looked all over and wasn't finding anything.  Maybe someday I'll be as comfortable with this as I am with PHP.

0
jfrank
5/28/2008 5:17:52 PM
Reply:

Similar Artilces:

Unable to make the session state request to the session state server
Hi all, I'm working on the website http://universityauction.net and I was using session variables using InProc session mode to manage session state. This worked fine until I put the website in a load balanced environment, as inproc sessions get lost when jumping from server to server. I decided to move to a state server mode, so I changed my web.config to: <sessionState             mode="StateServer"             stateConnectionString="tcpip=123.456.7.8:42424"      ...

Unable to make the session state request to the session state server.
 Hello,           I’m receiving this error when I put my website on production."Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same.  If the server is on a remote machine, please ensure that it accepts remote requests by checking the value of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters\AllowRemoteConnection.  If the server is on the local machine, and if the before men...

Error: Unable to make the session state request to the session state server
I have session configured in web.config this way:<sessionState mode="StateServer" cookieless="true", timeout="30" stateConnectionString="tcpip=127.0.0.1:42424" />  ASP.NET State Service is started.   I got an error:  Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same.  If the server is on a remote machine, please ensure that it accepts remote requests by checking the value of HKEY_LOCAL_MACHINE\SYSTEM\CurrentContr...

Unable to make the session state request to the session state server etc.
We are getting an error message "Unable to make the session state request to the session state server..." sporadically in one of our applications.  We have several applications running on a 4-server web farm, and these applications have been in production for a year, so it is not a problem that the server is not reachable, not started, not addressed correctly, etc etc etc. One of the applications *does* put a lot of large datasets into session state.  Is there a limit on the allowable size of a session/cached object?  Also, the application opens several windows at once, ...

Unable to make the session state request to the session state server #2
We have recently started receiving these errors in the event viewer. We are using the out of proc state server on the same machine. The errors become more frequent, almost like it snowballs until users cannot work. System Info: Windows Server 2003 Standard SP2 , 4 GB of RAM, IIS 6.0, Asp.Net 2.0. What I know for certain: The state server is started and running Recycling the app pool nor restarting IIS fixes the problem Rebooting the machine DOES temporarily fix the problem. I changed the stateNetworkTimeout from 10 to 20 in webconfig and that had no effect. There is usuall...

Unable to make the session state request to the session state server
 We have a web application in our school called CHECM. We are experiencing a high volume of ASP.NET State Server errors throughout this month. These errors have been occurring since 7/11/2006.   Our Session State Mode has been --------------------------------------------------------- <sessionState mode="StateServer" stateConnectionString="tcpip=CHECM:42424" timeout="20" stateNetworkTimeout="30"/>     Here is the Error we get randomly Exception: System.Web.HttpException Message: Unable to make the session state request to the session state server. P...

Passing Session State variables to html form
I'm trying to pass an "Amount" field from my dot net web form to another form which will send it to VeriSign's Payflow Link. It seems that their code works as long as I don't include the runat="server" on the form. Is there a way to pass Session State data from one form to a simple html form? Their code that works when I insert this in html view is: <form method="POST" action="https://payflowlink.verisign.com/payflowlink.cfm"> <input type="hidden" name="LOGIN" value="Your LOGIN here"> <input ...

State management upon session variable changes
I noticed that whenever a session variable is changed...the application knows about it and suddenly restarts session. My question is does restart "ALL" sessions or only the active sessions for which the variables changed? Imagine a "multi-user" application all with different states and an administration panel that lets you change session variables.  In this case, my question has to do with the question that if Company X changes his session variables, will only Company X's sessions be reset or will all "sessions" be reset?  Hope that makes sense. ...

Visual Studio 2005
 Hi, I have recently been given a PC with Vista on it, and installed Visual Studio 2005 pro. I then moved a ASP.net web project from an XP machine to the Vista one. When I run the project from inside Visual Studio (debug mode) everything works fine on the front end of the website, but if I try and log in I get the following error:  Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same.  If the server is on a remote machine, please ensure that i...

Session and View state values are changed: mixed with simultaneous users' session and viewstate values.
I have developed one aspx page(c#) that includes 7pages of the input form: each page is surrounded with panel control. It will be hidden or shown depending on which page the user wants to go. There are several update panels that contain gridview controls on the page. The source of the gridview is session value (arrayList). Whenever the page is postbacked by clicking previous and next buttons to show a certain page and hide other page panels, or adding new list data into the arrayList of the session value ( the value is retrieved on the pertaining gridview), the session and server control val...

Error message
Hello,I have developed an ASP.NET c# application.I have a "Reports" page in which i put the the report's DataTable in a session (to use it later on for paging and sorting).This works on my localhost but on production I get the follwong error:Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same.  If the server is on a remote machine, please ensure that it accepts remote requests by checking the value of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Servic...

Session variables vs. Session States
What is the difference and in what situations are they used. Thanks, Mattypee A session state (the state of your session) holds your session variables. If your session state expires (due to inactivity) then you lose your session variables...and any other info stored for that session. If you need to store USER specific information within a web app, then session variables are one(of several) ways to do it. MajorCatsMajorCats Is there any code that you could show that would give an example? Thanks, Mattypee example of what? reading and writing session variables? ...

Opinions on Viewstate vs. Session variable for state management on dataset
I came across many sample codes that using ViewState(myDataSet) and Session("myDataSet"). Which is a better way to use to keep the session around. What are the pros and cons? Anybody can share with your experience or thoughts? Thanks, teresa Take a loot at this article: State Management in Web Forms http://www.c-sharpcorner.com/Code/2004/Feb/StateManagementInWebForms.aspDarrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you!...

Good news for those of you who get "Unable to make the session state request to the session state server." error..
Dear all,Due to the known problem of session variables getting lost if using InProc-server during frequent changes in development, I had to choose between SQL and ASP.NET State server, so I opted for the second. Initially, all fine, but after using it for a few days, I started to get this error: Server Error in '/cv2' Application.Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same.  If the server is on a remote machine, please ensure that it accep...

Web resources about - Session variables not pointing to Request.Form Values - asp.net.state-management

Variable - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Westpac interest rate rise is one of many variable loan rate rises
WESTPAC is not alone in hitting its owner-occupier customers with a surprise interest rate rise, as dozens of other variable rate home loans ...

Airbnb upgrades variable pricing tool for hosts
Online home rental group Airbnb is rolling out an upgraded variable pricing tool that automatically raises or cuts room rates based on supply ...

Commonwealth Bank raises variable home loan rates
Home owners' mortgage costs are set to rise by hundreds of dollars a year, after the Commonwealth Bank became the latest bank to hike interest ...

CBA lifts variable home loan rates to offset costs associated with stricter capital requirements
The Commonwealth Bank to lift its home loan interest rates independently of the Reserve Bank to partially offset costs associated with stricter ...

Washington Square Signs Spielbergs, Choi Joins Variable and More
... films and an episode of the HBO comedy series "Girls," on which he plays the role of Ray Ploshansky. New York-based creative collective Variable ...

YouTube v10.32 Tweaks Some Interface Elements And Includes Hints About Virtual Reality Content And Variable ...
Forget Update Wednesday! Monday is the new big day. Not only were we treated to the latest M preview release and the official Marshmallow name, ...

"You have to ignore many variables to think women are paid less than men. California is happy to try." ...
Writes Sarah Ketterer in The Wall Street Journal in "The ‘Wage Gap’ Myth That Won’t Die" (which you can get to without subscribing if you Google ...

Cisco Debuts Open Pay Variable Pricing, Updates CCRE
Cisco Debuts Open Pay Variable Pricing, Updates CCRE Channel Partners Kris Snow, president of Cisco Capital, says the company's new Open Pay ...

Expert Reveals the Latest Variable Capacity Technology
Learn about gForce Ultra CRAC equipment, the latest variable capacity technology to lower energy usage and increase reliability.

Resources last updated: 11/26/2015 8:24:02 AM