Use Session and Server.Transfer to create a wizard : Session class « Sessions « ASP.NET Tutorial






<%@Page language="c#" runat="server" Debug="true" %>
<script runat="server">
protected void Page_Load(object o, EventArgs e) {
    if(IsPostBack) {
        Session["theName"] = (string)theName.Text;
        Server.Transfer("Default.aspx", false);
    }
}
</script>

<form runat="server">
    Name: <asp:textbox id="theName" runat="server" />
    <asp:button type="submit" id="submitStep1" runat="server" Text="Go"/>
</form>

File: Default.aspx


<%@Page language="c#" runat="server" %>
<script runat="server">
protected void Page_Load(object o, EventArgs e) {
    if(IsPostBack) {
    Session["theHobby"] = theHobby.Text;
    Server.Transfer("NextPage.aspx");
    }
}
</script>

<form runat="server">
    Hobby: <asp:textbox id="theHobby" runat="server"/>
    <asp:button type="submit" id="submitStep2" runat="server" Text="Go"/>
</form>

File: NextPage.aspx

<%@Page language="c#" runat="server" %>
<script runat="server">
protected void Page_Load(object o, EventArgs e) {
    theFinalName.Text = (string)Session["theName"];
    theFinalHobby.Text = (string)Session["theHobby"];   
}

</script>

<form runat="server">
Done!<br />
    Name: <asp:label id="theFinalName" runat="server" /><br/>
    Hobby: <asp:label id="theFinalHobby" runat="server" /><br/>
</form>








11.2.Session class
11.2.1.Session.Mode
11.2.2.Session.Abandon()
11.2.3.Use Session and Server.Transfer to create a wizard
11.2.4.Session.CodePage
11.2.5.Session.Contents.RemoveAll()
11.2.6.Session.CopyTo
11.2.7.Session.IsCookieless
11.2.8.Session.IsNewSession
11.2.9.Session.IsReadOnly
11.2.10.Session.Item
11.2.11.Session.Keys
11.2.12.Session.LCID
11.2.13.Session.Remove
11.2.14.Session.RemoveAll
11.2.15.Session.RemoveAt
11.2.16.Session.StaticObjects
11.2.17.Session.Timeout