MultiView::ActiveViewIndex Property

 

Gets or sets the index of the active View control within a MultiView control.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public:
property int ActiveViewIndex {
	virtual int get();
	virtual void set(int value);
}

Property Value

Type: System::Int32

The zero-based index of the active View control within a MultiView control. The default is -1, indicating that no view is set as active.

Exception Condition
ArgumentOutOfRangeException

The specified index was set to less than -1, or greater than or equal to the number of items on the list.

Use the ActiveViewIndex property to set a View control within a MultiView control as the active view. You can also use this property to return the index of the View control that is currently set as the active view. The index of a View control is determined by the order in which it is declared within a MultiView control. For example, the first View control declared within a MultiView control has an index of 0.

Only one View control at a time can be defined as active within a MultiView control. The View control that is set to the ActiveViewIndex property will be rendered to the client. If the ActiveViewIndex property is set to a View that does not exist within the MultiView control, a ArgumentOutOfRangeException is raised at run time. If the property is empty, the MultiView control does not render any content to the client.

You can set the ActiveViewIndex property either declaratively at development time or programmatically at run time. Setting the ActiveViewIndex property declaratively when you define the MultiView control causes the View control that is set as the active view to render to the client the first time the MultiView control is called. Setting the ActiveViewIndex property programmatically allows the application to determine which View control to render to the client at run time based on criteria such as a user's identity or their preferences.

Alternately, you can use the SetActiveView and GetActiveView methods to set or get the active view within the MultiView control.

The following code example demonstrates how to use a MultiView control to create a basic survey. Each View control is a separate survey question. When the user clicks the Previous button on any page, the ActiveViewIndex property is decremented to navigate to the previous View control. When the user clicks the Next button on any page, the ActiveViewIndex property is incremented to navigate to the next View control.

System_CAPS_noteNote

The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Forms Page Code Model.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top
Show: