MultiView.ActiveViewIndex Property
Assembly: System.Web (in system.web.dll)
/** @property */ public int get_ActiveViewIndex () /** @property */ public void set_ActiveViewIndex (int value)
public function get ActiveViewIndex () : int public function set ActiveViewIndex (value : int)
Not applicable.
Property Value
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.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.
| Topic | Location |
|---|---|
| How to: Add MultiView Web Server Controls to a Web Forms Page (Visual Studio) | Building ASP .NET Web Applications in Visual Studio |
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.
Note: |
|---|
| 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 Page Code Model. |
Note: