aspxtreme

Introduction to the MultiView and View Controls

Controls You Can Use on Web Forms   ASP.NET Standard Controls   MultiView and View Controls


The MultiView Web server control acts as an outer container for one or more View controls, which in turn can contain any combination of HTML and other controls. Together, these controls provide a way to easily present alternate views of information.

The MultiView and View controls are commonly used to perform the following tasks.

  1. Provide different sets of UI based on user preferrence or other conditions.
  2. Create a multi-page form.

In the first scenario, you might, for example, want to allow users to view different categories or subsets of information. You can then provide separate View controls to contain the information for each category, and display the corresponding View control based on, for instance, the user's choice. In this case, the MultiView and View controls are used as an alternative to creating multiple Panel controls.

In the second scenario, you might, for example, want to create a form that users fill in step by step. You can then provide separate View controls to contain the user input controls needed for each step, and display the required View control based on, for instance, a given condition. In this case, the MultiView and View controls are used to provide behavior that is similar to the Wizard control.

The MultiView control displays one View control at a time, exposing the content defined for the active View control. The active View control, i.e. the View control currently visible, is specified by setting the MultiView control's ActiveViewIndex property.

The following sections briefly introduce the main features of the MultiView and View controls.

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 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. Also, these controls do not support appearance properties that can be applied as a whole to the current View control. You can, however, 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. However, you can reference the controls in the View controls individually in code. For details, see Accessing ASP.NET Controls Programmatically.

Navigating Between Views

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 example shows use of a MultiView control with two View controls.

 Show me 

See Also

Adding MultiView Controls to a Web Forms Page



Books and more ...


Suggested Reading

Need a break ?



Previous page Back to top Next page

Check out related books at Amazon

© 2000-2008 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note