How to use MultiView Control in ASP.NET
In this article you will learn how to use MultiView control as a container for groups of View controls in ASP.NET.
ASP.NET MultiView Control
The MultiView control is used as a container for groups of View controls. It allows you to define a group of View controls, where each View control contains child controls but show only one at a time. To Navigate all the views, you need to put Buttons, LinkButton or ImageButton on the views with command as next and precious view.
In the following example I drop five views on Multiview control as you can see in the Fig 1.
Fig 1. MultiView with five Views
Now we put an image control to display image, a label to show its name and a command button to navigate the next image view.
<asp:MultiView ID="MultiView1" runat="server">
<asp:View ID="View1" runat="server">
<asp:Image ID="Image1" runat="server" img src="image1.jpg" Height="204px"
Width="291px" />
<br /><br />
<asp:Label ID="Label1" runat="server" Text="Image 1" Font-Size="Large"
ForeColor="#000099"></asp:Label>
<br /><br />
<asp:Button ID="Button1" runat="server" Text="Next Image" OnClick="NextImage" />
</asp:View>
</asp:MultiView>
MultiView's ActiveViewIndex property decides which view is active. As you see in the following code, I simply set the ActiveViewIndex property to 0 and then increase by 1 which represents first, second, third and so on Views respectively.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsPostBack Then
MultiView1.ActiveViewIndex = 0
End IfEnd Sub
Sub NextImage(ByVal sender As Object, ByVal e As System.EventArgs)
MultiView1.ActiveViewIndex += 1
End Sub
MultiView In Action
Fig 2. Multiview Control with View 1
Fig 3. Multiview Control with View 3