Skip to main content

How To Create A Simple Wizard Form using Panel and Viewstate

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Wizard.aspx.cs" Inherits="Wizard" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <title>Untitled Page</title>
</head>
<body>
   <form id="Form1" runat="server">
       <asp:Panel ID="P0" Visible="true" runat="server">
           Name:
           <input id="na" type="text" runat="server" />
           <br>
           <input id="Submit1" type="submit" value=" Next >> " onserverclick="a1" runat="server" />
       </asp:Panel>
       <asp:Panel ID="P1" Visible="false" runat="server">
           Address:
           <input id="a" type="text" runat="server" />
           <input id="Submit2" type="submit" value=" << Back " onserverclick="a2" runat="server" />
           <input id="Submit3" type="submit" value=" Next >> " onserverclick="a1" runat="server" />
       </asp:Panel>
       <asp:Panel ID="P2" Visible="false" runat="server">
           Card Number:
           <input id="n" type="text" runat="server" />
           <input id="Submit4" type="submit" value=" << Back " onserverclick="a2" runat="server" />
           <input id="Submit5" type="submit" value="   Finish   " onserverclick="a3" runat="server" />
       </asp:Panel>
   </form>
   <asp:Label ID="l" runat="server" />
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 Wizard : System.Web.UI.Page
{
   protected void Page_Load(Object Src, EventArgs E)
    {

        if (!IsPostBack)

            ViewState["zzz"] = 0;

    }

   protected void a1(Object Src, EventArgs E)
    {

        String pid = "P" + ViewState["zzz"].ToString();

        ViewState["zzz"] = (int)ViewState["zzz"] + 1;

        String Id = "P" + ViewState["zzz"].ToString();

        Panel p = (Panel)FindControl(Id);

        p.Visible = true;

        p = (Panel)FindControl(pid);

        p.Visible = false;

    }

   protected void a2(Object Src, EventArgs E)
    {

        String Id = "P" + ViewState["zzz"].ToString();

        ViewState["zzz"] = (int)ViewState["zzz"] - 1;

        String pid = "P" + ViewState["zzz"].ToString();

        Panel p = (Panel)FindControl(Id);

        p.Visible = false;

        p = (Panel)FindControl(pid);

        p.Visible = true;

    }

    protected void a3(Object Src, EventArgs E)
    {

        String s = "P" + ViewState["zzz"].ToString();

        Panel p = (Panel)FindControl(s);

        p.Visible = false;

        l.Text += "Name: " + na.Value + "<br>";

        l.Text += "Address: " + a.Value + "<br>";

        l.Text += "Card : " + n.Value + "<br>";

    }
}

Comments

Popular posts from this blog