Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

How to use Multiview Control in ASP.NET

0.00/5 (No votes)
23 Jul 2007 1  
The article describes how to use the Multiview server control in asp.net
Screenshot - MVC.jpg

Introduction

This article describes how to use the multiview server control in asp.net with c# as the backend

Background

The multiview control is a new feature of asp.net 2.0 which was introduced with visualstudio 2005.The main advantage of the multiview control is tnat we can specify the required view only(Ie display the required view only) on a single page.Multiview control helps us to create different views in the same page and display the view as the user clicks the links. With Multiview control the tab functionality is achived in asp.net.

Using the code

ASPX Code

<table border="0" cellpadding="2" cellspacing="3" width="100%">

<tr>
<td>
<asp:LinkButton ID="lnkTab1" runat="server" OnClick="lnkTab1_Click">Tab1</asp:LinkButton></td>
<td>
<asp:LinkButton ID="lnkTab2" runat="server" OnClick="lnkTab2_Click">Tab2</asp:LinkButton></td>
<td>
<asp:LinkButton ID="lnkTab3" runat="server" OnClick="lnkTab3_Click">Tab3</asp:LinkButton></td>
</tr>
<tr>
<td colspan="3">
<asp:MultiView ID="MultiView1" runat="server">
<table width="100%" cellpadding="2" cellspacing="5">
<tr>
<td>
<asp:View ID="View1" runat="server">
Content 1 goes here</asp:View>
</td>
<td>
<asp:View ID="View2" runat="server">
Content 2 goes here</asp:View>
</td>
<td>
<asp:View ID="View3" runat="server">
content 3 goes here</asp:View>
</td>
</tr>
</table>
</asp:MultiView></td>
</tr>
</table>

C# code

protected void Page_Load(object sender, EventArgs e)
{
  if (!IsPostBack)
   {
   SetDefaultView();
   }

}

private void SetDefaultView()
{
MultiView1.ActiveViewIndex = 0; 
}

protected void lnkTab1_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = 0; 
}
protected void lnkTab2_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = 1; 
}
protected void lnkTab3_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = 2;
}

 

Points of Interest

This is a cool new feature of ASP.NET 2.0,Try this.

History

Created by George Zacharia on 23/07/2007 .

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here