Articles → .NET → Multiview control in asp.net

Multiview control in asp.net










Prerequisite









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;
  }        
}









Click to Enlarge




Click to Enlarge




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