ASP.NET 3.5 Tabbed Pages

Tabbed pages are very useful to organize content pages. Many browsers and source editors (such as Eclipse or Microsoft Visual Web Developer) use them. They appear as shown in figure 1.

Code

Figure 1

We can obtain the Tabbed Pages effect just combining a MultiView control and 1 to n View controls: the MultiView control will act as the container of our content pages, and the View controls will be our content pages.

Let's start!!!

The first step is very simple, just put a MultiView control, n LinkButton controls, and n View controls on our page (n represents the number of tabbed pages we need) as shown in Figure 2. Note that View controls must be within the MultiView control.

View controls

Figure 2

Let's rename the inner text of the LinkButton controls with the name of the tabbed pages. The content of every tabbed page has to be placed between the <asp:View> and the </asp:View> tags (delete the current text "Tab n - insert your content here")

The second step is very simple as well. Just declare a TabManager variable and add to it every LinkButton you added in the previous step in the same order that they appear on our page. Have a look at the figure 3.

TabManager

Figure 3

Note that the constructor of the TabManager class needs three parameters: the MultiView we added in the first step, the color of the selected tab, and the color of the unselected tabs.

Now you can run your web page, it should appear as shown in Figure 4. You can add a CssClass attribute to every LinkButton if you don't like their look.

CssClass

Figure 4. The second tab is currently selected

Very simple, right?

You can stop reading this document just now if you are a simple user, but let's have a look at the TabManager class for most curious people (figure 5).

UI

Link button

Figure 5

The comments within the code explain carefully how the TabManager class works.

Enjoy your tabbed pages.


Similar Articles