Jaa


MultiView and View Web Server Controls Overview

The MultiView and View Web server controls act as containers for other controls and markup, and provide a way for you to easily present alternate views of information.

This topic contains:

  • Scenarios

  • Background

  • Code Examples

  • Class Reference

Scenarios

You can use the MultiView and View controls to perform tasks such as the following:

  • Provide alternate sets of controls based on user choice or other conditions. For example, you might allow users to select from a list of feeds, each of which is configured in a separate View control. You can then display the View control that contains the user's choice of feeds. You can use the MultiView and View controls as an alternative to creating multiple Panel controls.

  • Create a multi-page form. The MultiView and View controls can provide behavior that is similar to the Wizard control. The Wizard control is particularly suited to creating forms that users fill in step by step. The Wizard control also includes support for more built-in UI elements, such as a header and footer, for Previous and Next buttons, and for templates. You might use a MultiView control in place of a Wizard if you wanted to create a display that changed based on condition (rather than sequentially), or if you did not need the extra features supported by the Wizard control.

Back to top

Background

The MultiView control acts as an outer container for one or more View controls. The View controls, in turn, can contain any combination of markup and controls.

The MultiView control displays one View control at a time, exposing the markup and controls within that View control. By setting the MultiView control's ActiveViewIndex property, you can specify which View control is currently visible.

Rendering View Control Content

If a View control is not selected, it is not rendered to the page. However, instances of all Web server controls in all the View controls are created each time the page is rendered, and their values are stored as part of the page's view state.

Neither the MultiView control nor individual View controls render any markup to the page other than the contents of the current View control. For example, the controls do not render a div element in the same way that a Panel control does. They also do not support appearance properties that can be applied as a whole to the current View control. But you can assign a theme to the MultiView or View controls, which applies the theme to all child controls of the current View control.

Referencing Controls

Each View control supports a Controls property that contains a collection of the controls in that View control. You can also reference the controls in the View controls individually in code. For details, see Accessing ASP.NET Controls Programmatically.

You can move between views by setting the MultiView control's ActiveViewIndex property to the index value of the View control to display. The MultiView control also includes support for navigation buttons that you can add to each View control.

To create navigation buttons, you can add a button control (Button, LinkButton, or ImageButton) to each View control. You can then set the CommandName and CommandArgument properties of each button to reserved values to cause the MultiView control to move to another view. The following table lists the reserved CommandName values and the corresponding CommandArgument values.

CommandName value

CommandArgument value

NextView

(no value)

PrevView

(no value)

SwitchViewByID

ID of the View control to switch to.

SwitchViewByIndex

Index number of the View control to switch to.

The following code example shows a MultiView control with three View controls. Each View control contains a Button control that moves to a specific View control.

<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
  <asp:View ID="View1" runat="server">
    View 1<br />
    <br />
    <asp:Button ID="Button1" runat="server" 
      CommandArgument="View2" 
      CommandName="SwitchViewByID"
      Text="Go to View2" />
  </asp:View>
  <asp:View ID="View2" runat="server">
    View 2<br />
    <br />
    <asp:Button ID="Button2" runat="server" 
      CommandArgument="View3" 
      CommandName="SwitchViewByID"
      Text="Go to View 3" />
  </asp:View>
  <asp:View ID="View3" runat="server">
    View 3<br />
    <br />
    <asp:Button ID="Button3" runat="server" 
      CommandArgument="View1" 
      CommandName="SwitchViewByID"
      Text="Go to View 1" />
  </asp:View>
</asp:MultiView>

Back to top

Code Examples

How to: Add MultiView Web Server Controls to a Web Forms Page

Back to top

Class Reference

The following table lists the classes that relate to the MultiView and View controls.

Member

Description

MultiView

The main class for the MultiView control.

ViewCollection

Represents a collection that enables a MultiView control to maintain a list of its child controls.

View

The main class for the View control.

MultiViewControlBuilder

Interacts with the parser to build a MultiView control. To create a custom control builder for a MultiView derived control, you need to inherit from this class.

Back to top

See Also

Reference

Panel Web Server Control Overview

Wizard Web Server Control Overview