Articles → .NET → Multiview Control In Asp.Net

Multiview Control In Asp.Net










Prerequisite




  1. Visual studio 2005 (or higher versions of visual studio) should be installed on your machine.
  2. Hands on experience in creating a web application.

Multiview Control






Picture showing the diagrammatic representation of multiview control
Click to Enlarge


Syntax


<asp:MultiView ID="MULTIVIEW_ID" runat="server" ActiveViewIndex="0"><asp:View runat="server">
    <!-- Control or collection of controls -->
</asp:View>
<asp:View runat="server">
    <!-- Control or collection of controls -->
</asp:View>
<asp:View runat="server">
    <!-- Control or collection of controls -->
</asp:View></asp:MultiView>







Example


<asp:MultiView ID="mvMyView" runat="server" ActiveViewIndex="0"><asp:View runat="server"><asp:Login runat="server"></asp:Login></asp:View><asp:View runat="server"><asp:CreateUserWizard runat="server"></asp:CreateUserWizard></asp:View><asp:View runat="server"><asp:ChangePassword runat="server"></asp:ChangePassword></asp:View></asp:MultiView><asp:Button ID="btnPrevious" runat="server" Text="<<" onclick="btnPrevious_Click" /><asp:Button ID="btnNext" runat="server" Text=">>" onclick="btnNext_Click" />








protected void btnPrevious_Click(object sender, EventArgs e) {
  if (mvMyView.ActiveViewIndex > 0) {
    mvMyView.ActiveViewIndex = mvMyView.ActiveViewIndex - 1;
  }
}
protected void btnNext_Click(object sender, EventArgs e) {
  if (mvMyView.ActiveViewIndex < 2) {
    mvMyView.ActiveViewIndex = mvMyView.ActiveViewIndex + 1;
  }
}








Picture showing the first view of the multiview control
Click to Enlarge



Picture showing the second view of the multiview control
Click to Enlarge



Picture showing the third view of the multiview control
Click to Enlarge




Aspx Code


<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:MultiView ID="mvMyView" runat="server" ActiveViewIndex="0">
                    <asp:View runat="server">
                        <asp:Login runat="server"></asp:Login>
                    </asp:View>
                    <asp:View runat="server">
                        <asp:CreateUserWizard runat="server"></asp:CreateUserWizard>
                    </asp:View>
                    <asp:View runat="server">
                        <asp:ChangePassword runat="server"></asp:ChangePassword>
                    </asp:View>
                </asp:MultiView>
                <asp:Button ID="btnPrevious" runat="server" Text="<
                    <" onclick="btnPrevious_Click" />
                    <asp:Button ID="btnNext" runat="server" Text=">>" onclick="btnNext_Click" />
                </div>
            </form>
        </body></html>



Code Behind


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default: System.Web.UI.Page {
  protected void Page_Load(object sender, EventArgs e) {

  }
  protected void btnPrevious_Click(object sender, EventArgs e) {
    if (mvMyView.ActiveViewIndex > 0) {
      mvMyView.ActiveViewIndex = mvMyView.ActiveViewIndex - 1;
    }
  }
  protected void btnNext_Click(object sender, EventArgs e) {
    if (mvMyView.ActiveViewIndex < 2) {
      mvMyView.ActiveViewIndex = mvMyView.ActiveViewIndex + 1;
    }

  }
}



Posted By  -  Karan Gupta
 
Posted On  -  Thursday, October 20, 2011

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250