Fill and access Application-level data
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
Untitled Page
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void btnShowAppVariables_Click(object sender, EventArgs e)
{
Car appVars = ((Car)Application["CarSiteInfo"]);
string appState = string.Format("
Car on sale: {0}",appVars.currentName);
appState += string.Format("
Popular color: {0}",appVars.popularName);
appState += string.Format("
SalesPerson: {0}",appVars.firstName);
lblAppVariables.Text = appState;
}
protected void btnSetNewSP_Click(object sender, EventArgs e)
{
((Car)Application["CarSiteInfo"]).firstName = txtNewSP.Text;
}
}
File: Global.asax
<%@ Application Language="C#" %>
File: ~\App_Code\Car.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public class Car
{
public Car(string s, string c, string m)
{
firstName = s;
currentName = c;
popularName = m;
}
public string firstName;
public string currentName;
public string popularName;
}