<%@ Page %>
<script language="C#" runat="server">
private void Page_PreRender(object sender, EventArgs e)
{
if(Session["UserName"] != null) UserNameLabel.Text = Session["UserName"].ToString();
}
private void SaveButton_Click(object sender, System.EventArgs e)
{
Session["UserName"] = UserNameTextBox.Text;
}
private void AbandonButton_Click(object sender, System.EventArgs e)
{
Session.Abandon();
}
</script>
<html>
<body>
<form id="form1" method="post" runat="server">
Update UserName in Session: <asp:TextBox id="UserNameTextBox" runat="server"></asp:TextBox>
<asp:Button id="SaveButton" runat="server" Text="Save" OnClick="SaveButton_Click"></asp:Button>
Current Session Contents: <br/>
<asp:Label ID="UserNameLabel" Runat="server" EnableViewState="False"></asp:Label>
<br/>
<asp:Button id="RefreshButton" runat="server" Text="Refresh Without Saving"></asp:Button>
<br/>
Abandon Session - takes effect on *next* request since current request is still referring to Session.<br/>
<asp:Button id="AbandonButton" runat="server" Text="Abandon Session" OnClick="AbandonButton_Click"></asp:Button>
<a href="Default.aspx">VB Version - same session</a>
</form>
</body>
</html>