How to use MultiView control in asp.net

MultiView and View Server Control
MultiView is an asp.net web server control. The View control is also an asp.net web server control. But view control always is contained within multiview control. Both multiview and view control act as a container for other controls and markup. Only one view can be defined as an active view in MultiView. MultiView ActiveViewIndex property specifies the active view within view collections of a multiview. Only active view control is rendered to the page.

We can navigate views by setting the multiview ActiveViewIndex property value. ActiveViewIndex property holds the specified view's index number. MultiView control can include navigation buttons that we can add to each view.

We can create a navigation button by adding any Button, LinkButton, or ImageButton server control to each view. For that, we need to set the CommandName and CommandArgument properties of each view. Reserved CommandName values are NextView, PrevView, SwitchViewByID, and SwitchViewByIndex. NextView and PrevView corresponding CommandArgument have no values. SwitchViewByID CommandArgument value is the ID of the view to switch to. SwitchViewByIndex CommandArgument value is the index number of the view to switch to.

You can create a multi-page form using MultiView and view controls. But Wizard control is better for creating a multiple-page form that needs to fill step by step. MultiView and view control provide support similar to Wizard control. The Wizard has more built-in UI elements than multiview control. So MultiView is a better choice if we want to display a view based on condition rather than sequence.

The following example source code demonstrates to us how can we use MultiView and view controls in asp.net. In this web form, we create a multiview control and five view controls within it. Each view displays a beautiful image using Image server control. We also put a button control on each view to navigate views. When the user clicks the navigation button, the MultiView control displays the next view.
MultiView.aspx

<%@ Page Language="C#" %><!DOCTYPE html><script runat="server">    protected void Page_Load(object sender, System.EventArgs e) {        if(!Page.IsPostBack){            MultiView1.ActiveViewIndex = 0;           }    }    void NextImage(object sender, System.EventArgs e)    {        MultiView1.ActiveViewIndex += 1;    }    protected void Page_PreRender(object sender, System.EventArgs e) {        Label1.Text = "Beautiful birds images : " +            (MultiView1.ActiveViewIndex + 1).ToString() +            " of " + MultiView1.Views.Count.ToString();    }</script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title>How to use MultiView control in asp.net</title></head><body style="padding:25px">    <form id="form1" runat="server">    <div>        <h2 style="color:MidnightBlue; font-style:italic;">                  How to use MultiView        </h2>              <hr width="450" align="left" color="Gainsboro" />        <asp:Label            ID="Label1"            runat="server"            Font-Bold="true"            Font-Names="Comic Sans MS"            ForeColor="Crimson"            Font-Italic="true"            Font-Size="X-Large"            />        <br /><br />        <asp:MultiView ID="MultiView1" runat="server">            <asp:View ID="View1" runat="server">                <asp:Image                     ID="Image1"                     runat="server"                     ImageUrl="~/Images/birds1.jpg"                    Height="300"                    />                <br />                <asp:Button                     ID="Button1"                     runat="server"                     Text="Next Image"                     OnClick="NextImage"                    Font-Bold="true"                    ForeColor="Navy"                    Height="45"                    Width="150"                    />            </asp:View>            <asp:View ID="View2" runat="server">                <asp:Image                     ID="Image2"                     runat="server"                     ImageUrl="~/Images/birds2.jpg"                    Height="300"                    />                <br />                <asp:Button                     ID="Button2"                     runat="server"                     Text="Next Image"                     OnClick="NextImage"                    Font-Bold="true"                    ForeColor="Navy"                    Height="45"                    Width="150"                    />            </asp:View>            <asp:View ID="View3" runat="server">                <asp:Image                     ID="Image3"                     runat="server"                     ImageUrl="~/Images/birds3.jpg"                    Height="300"                    />                <br />                <asp:Button                     ID="Button3"                     runat="server"                     Text="Next Image"                     OnClick="NextImage"                    Font-Bold="true"                    ForeColor="Navy"                    Height="45"                    Width="150"                    />            </asp:View>            <asp:View ID="View4" runat="server">                <asp:Image                     ID="Image4"                     runat="server"                     ImageUrl="~/Images/birds4.jpg"                    Height="300"                    />                <br />                <asp:Button                     ID="Button4"                     runat="server"                     Text="Next Image"                     OnClick="NextImage"                    Font-Bold="true"                    ForeColor="Navy"                    Height="45"                    Width="150"                    />            </asp:View>            <asp:View ID="View5" runat="server">                <asp:Image                     ID="Image5"                     runat="server"                     ImageUrl="~/Images/birds5.jpg"                    Height="300"                    />            </asp:View>        </asp:MultiView>    </div>    </form></body></html>