locked
The name Session does not exist in the current context RRS feed

  • Question

  • I'm using VS2008 and have created several web pages for a web site.  For the two pages I am talking about both are content pages from the same master.  From one page I want to communicate with the other through the ASP session class.  In the page sending the information in an on click button routine I have
             Session["GenreName"] = WhichGenre;
    Where Which Gener is a string. Vs seems completely happy with this.
    In the page intended to recieve the information in the Page_Load I have
                ShowSessionGenre = Session["GenreName"].ToString;
    This gives me the error
    Error 1 The name 'Session' does not exist in the current context C:\Users\charles\Documents\Visual Studio 2008\WebSites\ClassLession1\Admin\EditGenre.aspx.cs 23 32 C:\...\ClassLession1\

    Both files have all the same using statements
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;

    Why doesn't VS like the second use of Session?
    Thanks,
    Chas
    • Moved by Peter Ritchie Thursday, October 9, 2008 3:11 PM ASP.NET specific question, should be on http://forums.asp.net/ (Moved from Visual C# General to Off-Topic Posts (Do Not Post Here))
    Wednesday, October 8, 2008 9:54 PM

Answers

  • Change

     ShowSessionGenre = Session["GenreName"].ToString;

    To

    ShowSessionGenre = Session["GenreName"].ToString();
    John Hidey - Dont forget to mark your threads when they are answered or helpful
    • Marked as answer by chas2003 Thursday, October 9, 2008 6:37 AM
    Thursday, October 9, 2008 12:43 AM

All replies

  • Change

     ShowSessionGenre = Session["GenreName"].ToString;

    To

    ShowSessionGenre = Session["GenreName"].ToString();
    John Hidey - Dont forget to mark your threads when they are answered or helpful
    • Marked as answer by chas2003 Thursday, October 9, 2008 6:37 AM
    Thursday, October 9, 2008 12:43 AM
  • Session lives on HttpContext.Current.Session.  On the Page class they just have a shortcut for it.  If this is a server control you can do a this.Page.Session or if from something else use HttpContext.Current.Session.


    http://msdn.microsoft.com/en-us/library/system.web.httpcontext.aspx
    Thursday, October 9, 2008 12:43 AM
  •    ShowSessionGenre.Text = Session["GenreName"].ToString();
    Did it.
    Thanks,
    Chas
    Thursday, October 9, 2008 6:37 AM
  • Thanks,
    Chas
    Thursday, October 9, 2008 6:37 AM