I am a new user of ASP.NET and was trying to segregate every page into variables, events and methods. I use a session variable that is used inside almost every method and event. So instead of extracting it from every method and storing it inside a variable, I tried to extract it on a page level. But the keyword 'Session' is not recognised outside a variable. Why is that?
public partial class OnCall_OnCall_History : System.Web.UI.Page
{
#region Variables
string ID = Convert.ToString(Session["ID"]); //Not allowed
#endregion
#region PageLoad
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string ID = (string)(Session["ID"]); //Allowed
}
}
#endregion
}