Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > Visual Studio 2005
|
Visual Studio 2005 For discussing Visual Studio 2005. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Studio 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 7th, 2006, 11:17 AM
Registered User
 
Join Date: Sep 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default SessionID changing between postbacks - C#

In my code, I have noticed that the SessionID is being changed as I move from page to page in the same browser. I duplicated this with a single form.

Add this to the form
 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
 <asp:Button ID="Button1" runat="server" Text="Button" />

In the Page_Load add
 TextBox1.Text = Session.SessionID.ToString();

As you click the Button, the SessionID changes. Why? I thought the SessionID was to be the same for the browser session?

 
Old September 20th, 2006, 11:23 AM
Authorized User
 
Join Date: Jan 2006
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you do a Google search, you'll see that there are several possible reasons for this. One possible reason is that you have to add at least one item to the Session object before either jumping to another page or before refreshing the current page.

For example:
Code:
protected void Page_Load(object sender, EventArgs e)
{
  if (Session["test"] == null) Session.Add("test", "yo");
  TextBox1.Text = Session.SessionID.ToString();
}
If you comment out the "if" statement above, you'll see a different SessionID every time you refresh the page.





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to reset the SessionID? akkad C# 2 October 24th, 2007 06:49 AM
nest radio button lists and postbacks lisabb ASP.NET 2.0 Basics 0 June 6th, 2007 11:41 AM
session.sessionid same for all items sarah lee ASP.NET 1.0 and 1.1 Basics 1 October 31st, 2006 12:40 PM
How To maintain dataset between postbacks debuajm ADO.NET 1 March 22nd, 2005 02:32 AM
How to Generate my own SESSIONID anand_asv .NET Framework 2.0 0 March 2nd, 2005 10:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.