Loading ...

Sessions

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  web forms / data controls   » Sessions

Sessions

Posts under the topic: Sessions

Posted: 11/25/2011

mk781
m k
Lurker 20  points  Lurker
  • Joined on: 11/25/2011
  • Posts: 4
Hi All,

A newbie in ASP.NET.

1. I have a textbox and a “Submit” button

2. When I enter text in the textarea and submit, in the event handler for the submit button my code then stores the value enetered in the textbox to a session.

3. I can sucessfully print the value stored in the session.However, if my “Submit” button goes to another page (which I have set via the PostBackUrl in properties using the Design View) in Visual Studio and try to print the same value from the session its empty.



Part of my code for the *first* page ( is in the aspx file and is below and IT WORKS if there is no PostBackUrl )

-------------------------------------------------------------------------------
<script runat="server">

protected void Button1_Click(object sender, EventArgs e)
{
Session["name"] = TextBox1.Text;
Response.Write("The value for the session you entered is : " + Session["name"].ToString());


}
</script>
----------------------------------------------

The following code on the Page_load for the *second* page is below (when the button is pressed is pressed from the *first* page)

----------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("The value for the session you entered is : " + Session["name"].ToString());
}
However this does not work. Any help is much appreciated

Posted: 11/27/2011

Guru 16813  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

Please format your question first to make it readable.


Posted: 12/21/2011

Professional 8338  points  Professional
  • Joined on: 4/15/2009
  • Posts: 424
  Answered

I haven't really used PostbackUrl of button. But I think the reason why your Session is empty its because when you set PostBackUrl it doesn't go to the Button Click event instead it will post directly to the Url where you set in the PostBackUrl property.


Page 1 of 1 (3 items)