Friday, December 16, 2005 11:27 AM
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 !!!