ASP.NET 2.0 MultiView Control - No more TabStrip / Panel Show-Hide

One of the most ignored or rather not talked about control in ASP.NET 2.0 (no more code name "whidbey") is the MultiView Control.

How many times we have wanted a scenario where we need to show only certain portions of a section and show the other based on a click event and allow users to toggle between the two. The solution for this in ASP.NET 1.X versions is to either go for a Tabstrip control or have a Button, Image Button etc., and have Panels which you can show and Hide.

Neither of the two were very efficient due to the following reasons.

Tabstrip
It wasnt a 100% solution for Tabbed Pages. It was a wonderful Web Control
but still had its own limitations.

Validators cannot exist happily across tabs where submission of neither of them will happen unless all the validators are satisfied.

You have to explicitly declare the Controls in the Code Behind unlike the traditional way, where you drag and drop a control and automatically, it adds the control declaration in the codebehind.

Microsoft does not support the IE Webcontrols and therefore there is no proper documentation / support for them and nor there is any reliability of performance.

Panels
You have to explicitly show a Panel and hide the other panels. Say you have 3 panels.

Then, you need to set Panel1.Visible = true and others Panel2.visible = false & Panel3.visible = false explicitly. You have to repeat these steps everytime you want to change between the panels.


Maintaining the Code becomes too tough if more panels get added.

ASP.NET 2.0 Provies a wonderful solution by means of MultiView Control. The MultiView Control combined with the View Control can provide different UI on different scenarios as and when required.

Herebelow, is the syntax for the same

<asp:MultiView ID="MultiView1" runat="server" >
<asp:View ID="View1" runat="server">
This is one section where you can have a set of controls / contents.
</asp:View>
<asp:View ID="View2" runat="server">
This is another section where you can have a different set of controls / contents.
</asp:View>
</asp:MultiView>

Now, to show the different tabs based on different events, we just need to set the following code:-

protected void Button1_Click(object sender, EventArgs e)
{
MultiView1.SetActiveView(View1);
}
protected void Button2_Click(object sender, EventArgs e)
{
MultiView1.SetActiveView(View2);
}

Thats all I need to show the different parts of the UI based on scenario. This is really useful in cases of Lengthy DataForms, collecting different information from different control types based on user's input.

The MultiView control for sure is going to change the way we have been coding heavily using Panels.

Cheers and Happy Programming !!!

Print | posted on Friday, December 16, 2005 11:27 AM

Comments on this post

# re: ASP.NET 2.0 MultiView Control - No more TabStrip / Panel Show-Hide

Requesting Gravatar...
Don't forget the Wizard control too!
Left by Brian on Dec 16, 2005 12:08 PM

# re: ASP.NET 2.0 MultiView Control - No more TabStrip / Panel Show-Hide

Requesting Gravatar...
Is it possible to use the multiview control within a Formview control?
I get errors trying to do so. Please help me out

rradhakrishnaiyer@rbi.org.in
Left by Radhakrishnan on Feb 21, 2007 7:30 AM

# re: ASP.NET 2.0 MultiView Control - No more TabStrip / Panel Show-Hide

Requesting Gravatar...










!


































Left by ! on Feb 14, 2008 10:57 PM

# re: ASP.NET 2.0 MultiView Control - No more TabStrip / Panel Show-Hide

Requesting Gravatar...
Nice Article. You are right its first time i hear about the Control, and the thing that made me google it is that it looked strange to me. well you just explain what it does, and i will have to figure out what are they using it for in my Application.

Thanks nice Article and Explain and a Simple example
Left by Vuyiswa Maseko on Jan 13, 2009 12:20 PM

# re: ASP.NET 2.0 MultiView Control - No more TabStrip / Panel Show-Hide

Requesting Gravatar...
I want to design a control that reads from a word 2007 file and shows it in default format in word file.Also this was a multiview control.
I dont know how to begin designng this control. if you can help me,it is so helpful for me.
thank alot.
Left by siavash on Jan 16, 2009 12:35 PM

# re: ASP.NET 2.0 MultiView Control - No more TabStrip / Panel Show-Hide

Requesting Gravatar...
Also this was a multiview control.
I dont know how to begin designng this control. if you can help me,it is so helpful for me.
Left by mario oyunları on Sep 21, 2009 10:47 AM

# re: ASP.NET 2.0 MultiView Control - No more TabStrip / Panel Show-Hide

Requesting Gravatar...
It is possible to use two are more formview control in multiview control it not showing the prop can any one help
Left by Dimitree on Mar 28, 2010 6:42 PM

# re: ASP.NET 2.0 MultiView Control - No more TabStrip / Panel Show-Hide

Requesting Gravatar...
Good Example
Left by Shafi on May 10, 2011 1:50 PM

# re: ASP.NET 2.0 MultiView Control - No more TabStrip / Panel Show-Hide

Requesting Gravatar...
Very informative post. It's really helpful for me and helped me lot to complete my task. Thanks for sharing with us. I had found another nice post over the internet which was also explained very well about View Control in ASP.Net, for more details of this post check out this link...

http://mindstick.com/Articles/35fb463b-8bca-4a53-a194-fc86f09899ee/?View%20Control%20in%20ASP.Net

Thanks everyone for your precious post.
Left by Somesh Batra on Jan 10, 2012 8:06 PM

Your comment:

 (will show your gravatar)