Click here to Skip to main content
15,868,016 members
Articles / Web Development / ASP.NET
Article

How to use Multiview Control in ASP.NET

Rate me:
Please Sign up or sign in to vote.
1.65/5 (13 votes)
23 Jul 2007 161.2K   21   10
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


Written By
Web Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 Pin
Reonekot10-Feb-14 22:50
Reonekot10-Feb-14 22:50 
SuggestionMulti view pointer Pin
Kanzz_25413-Jun-13 2:56
Kanzz_25413-Jun-13 2:56 
GeneralMy vote of 5 Pin
Vman27807-Jun-13 3:42
Vman27807-Jun-13 3:42 
GeneralNice Explain Pin
SinghAnuj5-Apr-13 19:53
SinghAnuj5-Apr-13 19:53 
QuestionMy Vote +5 Pin
Pr!y@15-Sep-12 8:01
Pr!y@15-Sep-12 8:01 
GeneralMy vote of 5 Pin
Prasad_Kulkarni14-Jun-12 0:31
Prasad_Kulkarni14-Jun-12 0:31 
GeneralMy vote of 1 Pin
ycano19-Jan-12 10:11
ycano19-Jan-12 10:11 
the same code of microsoft examples.
Question???? Pin
Ravindra_Parcha14-Jan-12 8:05
Ravindra_Parcha14-Jan-12 8:05 
Questionsub Pin
vinothharshad28-Jun-11 20:47
professionalvinothharshad28-Jun-11 20:47 
GeneralMy vote of 1 Pin
Milton_win18-Jun-09 21:52
Milton_win18-Jun-09 21:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.