MultiView 类

定义

表示作为一组 View 控件的容器的控件。

public ref class MultiView : System::Web::UI::Control
public class MultiView : System.Web.UI.Control
type MultiView = class
    inherit Control
Public Class MultiView
Inherits Control
继承
MultiView

示例

下面的代码示例演示如何使用 MultiView 控件创建基本调查。 每个 View 控件都是单独的调查问题。 当用户单击任何页面上的“ 上一个 ”按钮时, ActiveViewIndex 属性将递减以导航到上一 View 个控件。 当用户单击任何页面上的 “下一步 ”按钮时, ActiveViewIndex 属性将递增以导航到下一个 View 控件。

注意

以下代码示例使用单文件代码模型,如果直接复制到代码隐藏文件中,可能无法正常工作。 必须将此代码示例复制到扩展名为 .aspx 的空文本文件中。 有关Web Forms代码模型的详细信息,请参阅 ASP.NET Web Forms页代码模型

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>MultiView ActiveViewIndex Example</title>
<script runat="server">

  protected void NextButton_Command(object sender, EventArgs e)
  {
    // Determine which button was clicked
    // and set the ActiveViewIndex property to
    // the view selected by the user.
    if (DevPollMultiView.ActiveViewIndex > -1 & DevPollMultiView.ActiveViewIndex < 3)
    {
      // Increment the ActiveViewIndex property 
      // by one to advance to the next view.
      DevPollMultiView.ActiveViewIndex += 1;
    }
    else if (DevPollMultiView.ActiveViewIndex == 3)
    {
      // This is the final view.
      // The user wants to save the survey results.
      // Insert code here to save survey results.
      // Disable the navigation buttons.
      Page4Save.Enabled = false;
      Page4Restart.Enabled = false;
    }
    else
    {
      throw new Exception("An error occurred.");
    }
  }

  protected void BackButton_Command(object sender, EventArgs e)
  {
    if (DevPollMultiView.ActiveViewIndex > 0 & DevPollMultiView.ActiveViewIndex <= 2)
    {
      // Decrement the ActiveViewIndex property
      // by one to return to the previous view.
      DevPollMultiView.ActiveViewIndex -= 1;
    }
    else if (DevPollMultiView.ActiveViewIndex == 3)
    {
      // This is the final view.
      // The user wants to restart the survey.
      // Return to the first view.
      DevPollMultiView.ActiveViewIndex = 0;
    }
    else
    {
      throw new Exception("An error occurred.");
    }
  }

  </script>

</head>
<body>
    <form id="Form1" runat="Server">
        
        <h3>MultiView ActiveViewIndex Example</h3>
        
        <asp:Panel id="Page1ViewPanel" 
            Width="330px" 
            Height="150px"
            HorizontalAlign="Left"
            Font-size="12" 
            BackColor="#C0C0FF" 
            BorderColor="#404040"
            BorderStyle="Double"                     
            runat="Server">  

            <asp:MultiView id="DevPollMultiView"
                ActiveViewIndex="0"
                runat="Server">

                <asp:View id="Page1" 
                    runat="Server">   

                    <asp:Label id="Page1Label" 
                        Font-bold="true"                         
                        Text="What kind of applications do you develop?"
                        runat="Server"
                        AssociatedControlID="Page1">
                    </asp:Label><br /><br />

                    <asp:RadioButton id="Page1Radio1"
                         Text="Web Applications" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="server" >
                    </asp:RadioButton><br />

                    <asp:RadioButton id="Page1Radio2"
                         Text="Windows Forms Applications" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="server" >
                     </asp:RadioButton><br /><br /><br />                                       
                     
                    <asp:Button id="Page1Next"
                        Text = "Next"
                        OnClick="NextButton_Command"
                        Height="25"
                        Width="70"
                        runat= "Server">
                    </asp:Button>     
                          
                </asp:View>

                <asp:View id="Page2" 
                    runat="Server">

                    <asp:Label id="Page2Label" 
                        Font-bold="true"                        
                        Text="How long have you been a developer?"
                        runat="Server"
                        AssociatedControlID="Page2">                    
                    </asp:Label><br /><br />

                    <asp:RadioButton id="Page2Radio1"
                         Text="Less than five years" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="Server">
                     </asp:RadioButton><br />

                    <asp:RadioButton id="Page2Radio2"
                         Text="More than five years" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="Server">
                     </asp:RadioButton><br /><br /><br />

                    <asp:Button id="Page2Back"
                        Text = "Previous"
                        OnClick="BackButton_Command"
                        Height="25"
                        Width="70"
                        runat= "Server">
                    </asp:Button> 

                    <asp:Button id="Page2Next"
                        Text = "Next"
                        OnClick="NextButton_Command"
                        Height="25"
                        Width="70"
                        runat="Server">
                    </asp:Button> 
                
                </asp:View>

                <asp:View id="Page3" 
                    runat="Server">

                    <asp:Label id="Page3Label1" 
                        Font-bold="true"                        
                        Text= "What is your primary programming language?"                        
                        runat="Server"
                        AssociatedControlID="Page3">                    
                    </asp:Label><br /><br />

                    <asp:RadioButton id="Page3Radio1"
                         Text="Visual Basic .NET" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="Server">
                     </asp:RadioButton><br />

                    <asp:RadioButton id="Page3Radio2"
                         Text="C#" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="Server">
                     </asp:RadioButton><br />

                    <asp:RadioButton id="Page3Radio3"
                         Text="C++" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="Server">
                     </asp:RadioButton><br /><br />

                     <asp:Button id="Page3Back"
                        Text = "Previous"
                        OnClick="BackButton_Command"
                        Height="25"
                        Width="70"
                        runat="Server">
                    </asp:Button> 

                    <asp:Button id="Page3Next"
                        Text = "Next"
                        OnClick="NextButton_Command"
                        Height="25"
                        Width="70"
                        runat="Server">
                    </asp:Button><br />
                    
                </asp:View>     
            
                <asp:View id="Page4"
                    runat="Server">
                    
                    <asp:Label id="Label1"
                        Font-bold="true"                                           
                        Text = "Thank you for taking the survey."
                        runat="Server"
                        AssociatedControlID="Page4">
                    </asp:Label>
                    
                    <br /><br /><br /><br /><br /><br />              
                   
                    <asp:Button id="Page4Save"
                        Text = "Save Responses"
                        OnClick="NextButton_Command"
                        Height="25"
                        Width="110"
                        runat="Server">
                    </asp:Button>
                
                    <asp:Button id="Page4Restart"
                        Text = "Retake Survey"
                        OnClick="BackButton_Command"
                        Height="25"
                        Width="110"
                        runat= "Server">
                    </asp:Button>                    
                    
                </asp:View>  
       
            </asp:MultiView>
        
        </asp:Panel> 

    </form>
</body>
</html>
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>MultiView ActiveViewIndex Example</title>
<script runat="server">

        Sub NextButton_Command(sender As Object, e As System.EventArgs)
            ' Determine which button was clicked
            ' and set the ActiveViewIndex property to
            ' the view selected by the user.
            If (DevPollMultiView.ActiveViewIndex > -1) AND DevPollMultiView.ActiveViewIndex < 3 Then
                ' Increment the ActiveViewIndex property 
                ' by one to advance to the next view.
                DevPollMultiView.ActiveViewIndex += 1
            ElseIf DevPollMultiView.ActiveViewIndex = 3 Then
                ' This is the final view.
                ' The user wants to save the survey results.
                ' Insert code here to save survey results.
                ' Disable the navigation buttons.
                Page4Save.Enabled = False
                Page4Restart.Enabled = False
            Else
                Throw New Exception("An error occurred.")

            End If

        End Sub

        Sub BackButton_Command(ByVal sender As Object, ByVal e As System.EventArgs)
            If (DevPollMultiView.ActiveViewIndex > 0) And DevPollMultiView.ActiveViewIndex <= 2 Then
                ' Decrement the ActiveViewIndex property
                ' by one to return to the previous view.
                DevPollMultiView.ActiveViewIndex -= 1
            ElseIf DevPollMultiView.ActiveViewIndex = 3 Then
                ' This is the final view.
                ' The user wants to restart the survey.
                ' Return to the first view.
                DevPollMultiView.ActiveViewIndex = 0
            Else
                Throw New Exception("An error occurred.")

            End If

        End Sub

</script>

</head>
<body>
    <form id="Form1" runat="Server">
        
        <h3>MultiView ActiveViewIndex Example</h3>
        
        <asp:Panel id="Page1ViewPanel" 
            Width="330px" 
            Height="150px"
            HorizontalAlign ="Left"
            Font-size="12" 
            BackColor="#C0C0FF" 
            BorderColor="#404040"
            BorderStyle="Double"                     
            runat="Server">  

            <asp:MultiView id="DevPollMultiView"
                ActiveViewIndex="0"
                runat="Server">

                <asp:View id="Page1" 
                    runat="Server">   

                    <asp:Label id="Page1Label" 
                        Font-bold="true"                         
                        Text="What kind of applications do you develop?"
                        runat="Server"
                        AssociatedControlID="Page1">
                    </asp:Label><br /><br />

                    <asp:RadioButton id="Page1Radio1"
                         Text="Web Applications" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="server" >
                    </asp:RadioButton><br />

                    <asp:RadioButton id="Page1Radio2"
                         Text="Windows Forms Applications" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="server" >
                     </asp:RadioButton><br /><br /><br />                                       
                     
                    <asp:Button id="Page1Next"
                        Text = "Next"
                        OnClick="NextButton_Command"
                        Height="25"
                        Width="70"
                        runat= "Server">
                    </asp:Button>     
                          
                </asp:View>

                <asp:View id="Page2" 
                    runat="Server">

                    <asp:Label id="Page2Label" 
                        Font-bold="true"                        
                        Text="How long have you been a developer?"
                        runat="Server"
                        AssociatedControlID="Page2">                    
                    </asp:Label><br /><br />

                    <asp:RadioButton id="Page2Radio1"
                         Text="Less than five years" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="Server">
                     </asp:RadioButton><br />

                    <asp:RadioButton id="Page2Radio2"
                         Text="More than five years" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="Server">
                     </asp:RadioButton><br /><br /><br />

                    <asp:Button id="Page2Back"
                        Text = "Previous"
                        OnClick="BackButton_Command"
                        Height="25"
                        Width="70"
                        runat= "Server">
                    </asp:Button> 

                    <asp:Button id="Page2Next"
                        Text = "Next"
                        OnClick="NextButton_Command"
                        Height="25"
                        Width="70"
                        runat="Server">
                    </asp:Button> 
                
                </asp:View>

                <asp:View id="Page3" 
                    runat="Server">

                    <asp:Label id="Page3Label1" 
                        Font-bold="true"                        
                        Text= "What is your primary programming language?"                        
                        runat="Server"
                        AssociatedControlID="Page3">                    
                    </asp:Label><br /><br />

                    <asp:RadioButton id="Page3Radio1"
                         Text="Visual Basic .NET" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="Server">
                     </asp:RadioButton><br />

                    <asp:RadioButton id="Page3Radio2"
                         Text="C#" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="Server">
                     </asp:RadioButton><br />

                    <asp:RadioButton id="Page3Radio3"
                         Text="C++" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="Server">
                     </asp:RadioButton><br /><br />

                     <asp:Button id="Page3Back"
                        Text = "Previous"
                        OnClick="BackButton_Command"
                        Height="25"
                        Width="70"
                        runat="Server">
                    </asp:Button> 

                    <asp:Button id="Page3Next"
                        Text = "Next"
                        OnClick="NextButton_Command"
                        Height="25"
                        Width="70"
                        runat="Server">
                    </asp:Button><br />
                    
                </asp:View>     
            
                <asp:View id="Page4"
                    runat="Server">
                    
                    <asp:Label id="Label1"
                        Font-bold="true"                                           
                        Text = "Thank you for taking the survey."
                        runat="Server"
                        AssociatedControlID="Page4">
                    </asp:Label>
                    
                    <br /><br /><br /><br /><br /><br />              
                   
                    <asp:Button id="Page4Save"
                        Text = "Save Responses"
                        OnClick="NextButton_Command"
                        Height="25"
                        Width="110"
                        runat="Server">
                    </asp:Button>
                
                    <asp:Button id="Page4Restart"
                        Text = "Retake Survey"
                        OnClick="BackButton_Command"
                        Height="25"
                        Width="110"
                        runat= "Server">
                    </asp:Button>                    
                    
                </asp:View>  
       
            </asp:MultiView>
        
        </asp:Panel> 

    </form>
</body>
</html>

下面的代码示例演示如何创建包含三View个控件的基本MultiView控件。 用户从列表框中选择的视图将设置为活动视图,并向用户显示。 有关 控件的 MultiView 更详细示例,请参阅本主题中提供的其他代码示例。

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>MultiView Class Example</title>
<script runat="server">

        Sub Index_Changed(ByVal Sender As Object, ByVal e As EventArgs)
            ' Set the active view to
            ' the view selected by the user.
            Dim text As String = ViewListBox.SelectedItem.Text
            Select Case (text)
                Case "View1"
                    MultiView1.SetActiveView(View1)
                Case "View2"
                    MultiView1.SetActiveView(View2)
                Case "View3"
                    MultiView1.SetActiveView(View3)
                Case Else
                    Throw New Exception("You did not select a valid view.")
            End Select

        End Sub

    </script>
</head>
<body>
    <form id="Form1" runat="server">
        
        <h3>MultiView Class Example</h3>
        
        <h4>Select a View to display in a MultiView control:</h4>

        <asp:ListBox id="ViewListBox" 
            Rows="1"
            SelectionMode="Single"
            AutoPostBack="True"
            OnselectedIndexChanged="Index_Changed"
            runat="Server">             
                <asp:ListItem Value="0">View1</asp:ListItem>
                <asp:ListItem Value="1">View2</asp:ListItem>
                <asp:ListItem Value="2">View3</asp:ListItem>
        </asp:ListBox><br /><br />
       
        <hr />

        <asp:MultiView id="MultiView1"
            runat="Server">

            <asp:View id="View1" 
                runat="Server">              
                    <asp:Label id="View1Label" 
                        Font-bold="true"
                        Font-size="14" 
                        Text="This is the content for View1."
                        runat="Server"
                        AssociatedControlID="View1">
                    </asp:Label>               
            </asp:View>
            
            <asp:View id="View2" 
                runat="Server">              
                    <asp:Label id="View2Label" 
                        Font-bold="true"
                        Font-size="14" 
                        Text="This is the content for View2."
                        runat="Server"
                        AssociatedControlID="View2">
                    </asp:Label>               
            </asp:View>
            
            <asp:View id="View3" 
                runat="Server">              
                    <asp:Label id="View3Label" 
                        Font-bold="true"
                        Font-size="14" 
                        Text="This is the content for View3."
                        runat="Server"
                        AssociatedControlID="View3">
                    </asp:Label>               
            </asp:View>

        </asp:MultiView>

    </form>
</body>
</html>

下面的代码示例演示如何创建包含三ViewMultiView控件的控件。 控件 View 没有任何样式属性。 因此,每个 View 控件都包含一个 Panel 控件,用于在控件上 View 设置样式。 首次加载页面时, DefaultView 使用 SetActiveView 方法将 设置为活动视图。 每个 View 控件都包含链接按钮,允许用户导航到不同的视图。

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>MultiView Class Example</title>
<script runat="server">

        Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
            ' The first time the page loads,
            ' render the DefaultView.
            If Not IsPostBack Then
                ' Set DefaultView as the active view.
                MultiView1.SetActiveView(DefaultView)
            End If

        End Sub

        Sub LinkButton_Command(sender As Object, e As System.Web.UI.WebControls.CommandEventArgs)
            ' Determine which link button was clicked
            ' and set the active view to
            ' the view selected by the user.
            Select Case (e.CommandArgument)
                Case "DefaultView"
                    MultiView1.SetActiveView(DefaultView)
                Case "News"
                    MultiView1.SetActiveView(NewsView)
                Case "Shopping"
                    MultiView1.SetActiveView(ShoppingView)
                Case Else
                    Throw New Exception("You did not select a valid list item.")

            End Select

        End Sub

</script>

</head>
<body>
    <form id="Form1" runat="server">
        
        <h3>MultiView Class Example</h3>

        <asp:MultiView id="MultiView1"
            runat="Server">

            <asp:View id="DefaultView" 
                runat="Server">                

                <asp:Panel id="DefaultViewPanel" 
                    Width="330px" 
                    BackColor="#C0C0FF" 
                    BorderColor="#404040"
                    BorderStyle="Double"
                    runat="Server">  

                    <asp:Label id="DefaultLabel1" 
                        Font-bold="true"
                        Font-size="14" 
                        Text="The Default View"
                        runat="Server"
                        AssociatedControlID="DefaultView">
                    </asp:Label>                  

                    <asp:BulletedList id="DefaultBulletedList1" 
                        BulletStyle="Disc" 
                        DisplayMode="Hyperlink"
                        Target="_blank"
                        runat="Server">
                            <asp:ListItem Value="http://www.microsoft.com">Today's Weather</asp:ListItem>
                            <asp:ListItem Value="http://www.microsoft.com">Today's Stock Quotes</asp:ListItem>
                            <asp:ListItem Value="http://www.microsoft.com">Today's News Headlines</asp:ListItem>
                            <asp:ListItem Value="http://www.microsoft.com">Today's Featured Shopping</asp:ListItem>
                    </asp:BulletedList>

                    <hr />

                    <asp:Label id="DefaultLabel2"                      
                        Font-size="12" 
                        Text="Click a link to display a different view:"
                        runat="Server">
                    </asp:Label><br />
                
                    <asp:LinkButton id="Default_NewsLink" 
                        Text="Go to News View" 
                        OnCommand="LinkButton_Command"
                        CommandArgument="News" 
                        CommandName="Link"
            Width="150px"
                        runat="Server">
                    </asp:LinkButton>

                    <asp:LinkButton id="Default_ShoppingLink"
                        Text="Go to Shopping View" 
                        OnCommand="LinkButton_Command"
                        CommandArgument="Shopping" 
                        CommandName="Link"
            Width="150px"
                        runat="server">
                    </asp:LinkButton><br /><br />

                </asp:Panel>

            </asp:View>

            <asp:View id="NewsView" 
                runat="Server">

                <asp:Panel id="NewsPanel1" 
                    Width="330px" 
                    BackColor="#C0FFC0" 
                    BorderColor="#404040"
                    BorderStyle="Double"
                    runat="Server">

                    <asp:Label id="NewsLabel1" 
                        Font-bold="true"
                        Font-size="14"
                        Text="The News View"
                        runat="Server"
                        AssociatedControlID="NewsView">                    
                    </asp:Label>

                    <asp:BulletedList id="NewsBulletedlist1" 
                        BulletStyle="Disc" 
                        DisplayMode="Hyperlink"
                        Target="_blank"
                        runat="Server">
                            <asp:ListItem Value="http://www.microsoft.com">Today's International Headlines</asp:ListItem>
                            <asp:ListItem Value="http://www.microsoft.com">Today's National Headlines</asp:ListItem>
                            <asp:ListItem Value="http://www.microsoft.com">Today's Local News</asp:ListItem>
                    </asp:BulletedList>

                    <hr />

                    <asp:Label id="NewsLabel2"                      
                        Font-size="12" 
                        Text="Click a link to display a different view:"
                        runat="Server">
                    </asp:Label><br />

                    <asp:LinkButton id="News_DefaultLink" 
                        Text="Go to the Default View" 
                        OnCommand="LinkButton_Command"
                        CommandArgument="DefaultView" 
                        CommandName="Link"
                        Width="150px"
                        runat="Server">
                    </asp:LinkButton>

                    <asp:LinkButton id="News_ShoppingLink" 
                        Text="Go to Shopping View" 
                        OnCommand="LinkButton_Command"
                        CommandArgument="Shopping" 
                        CommandName="Link"
                        Width="150px"
                        runat="Server">
                    </asp:LinkButton><br /><br />

                </asp:Panel>

            </asp:View>

            <asp:View id="ShoppingView" 
                runat="Server">

                <asp:Panel id="ShoppingPanel1" 
                    Width="330px" 
                    BackColor="#FFFFC0" 
                    BorderColor="#404040"
                    BorderStyle="Double"
                    runat="Server">

                    <asp:Label id="ShoppingLabel1" 
                        Font-Bold="true"
                        Font-size="14"                         
                        Text="The Shopping View"
                        runat="Server"
                        AssociatedControlID="ShoppingView">
                    </asp:Label>

                    <asp:BulletedList id="ShoppingBulletedlist1" 
                        BulletStyle="Disc" 
                        DisplayMode="Hyperlink"
                        Target="_blank"
                        runat="Server">
                            <asp:ListItem Value="http://www.microsoft.com">Shop for Home and Garden </asp:ListItem>
                            <asp:ListItem Value="http://www.microsoft.com">Shop for Women's Fashions</asp:ListItem>
                            <asp:ListItem Value="http://www.microsoft.com">Shop for Men's Fashions</asp:ListItem>
                    </asp:BulletedList>

                    <hr />

                    <asp:Label id="ShoppingLabel2" 
                        Font-size="12" 
                        Text="Click a link to display a different view:"
                        runat="Server">
                    </asp:Label><br />

                    <asp:LinkButton id="Shopping_DefaultLink" 
                        Text="Go to the Default View" 
                        OnCommand="LinkButton_Command"
                        CommandArgument="DefaultView" 
                        CommandName="Link"
                        Width="150px"
                        runat="Server">
                    </asp:LinkButton>

                    <asp:LinkButton id="Shopping_NewsLink"
                        Text="Go to News View" 
                        OnCommand="LinkButton_Command"
                        CommandArgument="News" 
                        CommandName="Link"
                        Width="150px"
                        runat="Server">
                    </asp:LinkButton><br /><br />

                </asp:Panel>

            </asp:View>

        </asp:MultiView>

    </form>
</body>
</html>

注解

本主题内容:

介绍

控件 MultiView 是一组控件的 View 容器。 它允许定义一组 View 控件,其中每个 View 控件都包含子控件。 然后,应用程序可以根据用户标识、用户首选项和查询字符串参数中传递的信息等条件向客户端呈现特定的 View 控件。 还可以使用 MultiView 控件创建向导。 在此方案中,控件中包含的MultiView每个控件都View表示向导中的不同步骤或页面。 还应使用此控件为移动设备开发多屏幕应用程序。 此控件提供的功能与 .NET Framework 版本 1.1 中的 ASP.NET 移动Form控件相同。

一次只能将一个 View 控件定义为控件中的 MultiView 活动视图。 View将控件定义为活动视图时,它将包含的子控件呈现给客户端。 可以使用 ActiveViewIndex 属性或 SetActiveView 方法定义活动视图。 ActiveViewIndex如果 属性为空,则MultiView控件不会向客户端呈现任何内容。 如果活动视图设置为 View 控件中不存在的 MultiViewArgumentOutOfRangeException 则会在运行时引发 。

可以通过声明方式或编程方式定义活动视图。 ActiveViewIndex在定义MultiView控件时以声明方式设置 属性会导致View设置为活动视图的控件在首次调用控件时MultiView呈现给客户端。 下面的代码示例演示如何以声明方式设置 ActiveViewIndex 属性。

<asp:MultiView id="MultiView1" ActiveViewIndex=0 runat="Server">   

ActiveViewIndex以编程方式设置 属性或调用 SetActiveView 方法允许应用程序根据用户标识或首选项等条件确定View在运行时要呈现给客户端的控件。

若要允许用户在控件中的控件之间View导航,可以向每个View控件添加 LinkButtonButton 控件。MultiView 若要利用 MultiView 控件对当前活动的 View自动更新,请将按钮或链接按钮上的 属性设置为 CommandName 对应于所需导航行为的以下命令名称字段之一的值: PreviousViewCommandNameNextViewCommandNameSwitchViewByIDCommandNameSwitchViewByIndexCommandName

声明性语法

<asp:MultiView  
    ActiveViewIndex="integer"  
    EnableTheming="True|False"  
    EnableViewState="True|False"  
    ID="string"  
    OnActiveViewChanged="ActiveViewChanged event handler"  
    OnDataBinding="DataBinding event handler"  
    OnDisposed="Disposed event handler"  
    OnInit="Init event handler"  
    OnLoad="Load event handler"  
    OnPreRender="PreRender event handler"  
    OnUnload="Unload event handler"  
    runat="server"  
    SkinID="string"  
    Visible="True|False"  
>  
            <asp:TemplatedWizardStep  
                AllowReturn="True|False"  
                ContentTemplateContainer="string"  
                EnableTheming="True|False"  
                EnableViewState="True|False"  
                ID="string"  
                OnActivate="Activate event handler"  
                OnDataBinding="DataBinding event handler"  
                OnDeactivate="Deactivate event handler"  
                OnDisposed="Disposed event handler"  
                OnInit="Init event handler"  
                OnLoad="Load event handler"  
                OnPreRender="PreRender event handler"  
                OnUnload="Unload event handler"  
                runat="server"  
                SkinID="string"  
                StepType="Auto|Complete|Finish|Start|Step"  
                Title="string"  
                Visible="True|False"  
>  
                        <ContentTemplate>  
                            <!-- child controls -->  
                        </ContentTemplate>  
                        <CustomNavigationTemplate>  
                            <!-- child controls -->  
                        </CustomNavigationTemplate>  
            </asp:TemplatedWizardStep>  
            <asp:View  
                EnableTheming="True|False"  
                EnableViewState="True|False"  
                ID="string"  
                OnActivate="Activate event handler"  
                OnDataBinding="DataBinding event handler"  
                OnDeactivate="Deactivate event handler"  
                OnDisposed="Disposed event handler"  
                OnInit="Init event handler"  
                OnLoad="Load event handler"  
                OnPreRender="PreRender event handler"  
                OnUnload="Unload event handler"  
                runat="server"  
                SkinID="string"  
                Visible="True|False"  
            />  
            <asp:WizardStep  
                AllowReturn="True|False"  
                EnableTheming="True|False"  
                EnableViewState="True|False"  
                ID="string"  
                OnActivate="Activate event handler"  
                OnDataBinding="DataBinding event handler"  
                OnDeactivate="Deactivate event handler"  
                OnDisposed="Disposed event handler"  
                OnInit="Init event handler"  
                OnLoad="Load event handler"  
                OnPreRender="PreRender event handler"  
                OnUnload="Unload event handler"  
                runat="server"  
                SkinID="string"  
                StepType="Auto|Complete|Finish|Start|Step"  
                Title="string"  
                Visible="True|False"  
            />  
</asp:MultiView>  

构造函数

MultiView()

初始化 MultiView 类的新实例。

字段

NextViewCommandName

表示要显示在 View 控件中、与下一个 MultiView 控件关联的命令名。 此字段为只读。

PreviousViewCommandName

表示要显示在 View 控件中、与上一个 MultiView 控件关联的命令名。 此字段为只读。

SwitchViewByIDCommandName

表示与根据指定的 View ID 更改控件中的MultiView活动View控件关联的命令名称。此字段是只读的。

SwitchViewByIndexCommandName

表示命令名,该命令名与更改 View 控件的活动 MultiView 控件关联,这种更改是根据指定的 View 索引进行的。 此字段为只读。

属性

ActiveViewIndex

获取或设置 View 控件的活动 MultiView 控件的索引。

Adapter

获取控件的浏览器特定适配器。

(继承自 Control)
AppRelativeTemplateSourceDirectory

获取或设置包含该控件的 PageUserControl 对象的应用程序相对虚拟目录。

(继承自 Control)
BindingContainer

获取包含该控件的数据绑定的控件。

(继承自 Control)
ChildControlsCreated

获取一个值,该值指示是否已创建服务器控件的子控件。

(继承自 Control)
ClientID

获取由 ASP.NET 生成的 HTML 标记的控件 ID。

(继承自 Control)
ClientIDMode

获取或设置用于生成 ClientID 属性值的算法。

(继承自 Control)
ClientIDSeparator

获取一个字符值,该值表示 ClientID 属性中使用的分隔符字符。

(继承自 Control)
Context

为当前 Web 请求获取与服务器控件关联的 HttpContext 对象。

(继承自 Control)
Controls

获取 ControlCollection 对象,该对象表示 UI 层次结构中的指定服务器控件的子控件。

(继承自 Control)
DataItemContainer

如果命名容器实现 IDataItemContainer,则获取对命名容器的引用。

(继承自 Control)
DataKeysContainer

如果命名容器实现 IDataKeysControl,则获取对命名容器的引用。

(继承自 Control)
DesignMode

获取一个值,该值指示是否正在使用设计图面上的一个控件。

(继承自 Control)
EnableTheming

获取或设置一个值,该值指示是否向 MultiView 控件应用主题。

EnableViewState

获取或设置一个值,该值指示服务器控件是否向发出请求的客户端保持自己的视图状态以及它所包含的任何子控件的视图状态。

(继承自 Control)
Events

获取控件的事件处理程序委托列表。 此属性为只读。

(继承自 Control)
HasChildViewState

获取一个值,该值指示当前服务器控件的子控件是否具有任何已保存的视图状态设置。

(继承自 Control)
ID

获取或设置分配给服务器控件的编程标识符。

(继承自 Control)
IdSeparator

获取用于分隔控件标识符的字符。

(继承自 Control)
IsChildControlStateCleared

获取一个值,该值指示该控件中包含的控件是否具有控件状态。

(继承自 Control)
IsTrackingViewState

获取一个值,用于指示服务器控件是否会将更改保存到其视图状态中。

(继承自 Control)
IsViewStateEnabled

获取一个值,该值指示是否为该控件启用了视图状态。

(继承自 Control)
LoadViewStateByID

获取一个值,该值指示控件是否通过 ID 而不是索引参与加载其视图状态。

(继承自 Control)
NamingContainer

获取对服务器控件的命名容器的引用,此引用创建唯一的命名空间,以区分具有相同 ID 属性值的服务器控件。

(继承自 Control)
Page

获取对包含服务器控件的 Page 实例的引用。

(继承自 Control)
Parent

获取对页 UI 层次结构中服务器控件的父控件的引用。

(继承自 Control)
RenderingCompatibility

获取一个值,该值指定呈现的 HTML 将与之兼容的 ASP.NET 版本。

(继承自 Control)
Site

获取容器信息,该容器在呈现于设计图面上时承载当前控件。

(继承自 Control)
SkinID

获取或设置要应用于控件的外观。

(继承自 Control)
TemplateControl

获取或设置对包含该控件的模板的引用。

(继承自 Control)
TemplateSourceDirectory

获取包含当前服务器控件的 PageUserControl 的虚拟目录。

(继承自 Control)
UniqueID

获取服务器控件的唯一的、以分层形式限定的标识符。

(继承自 Control)
ValidateRequestMode

获取或设置指示控件是否检查来自浏览器的客户端输入是否具有潜在危险值的值。

(继承自 Control)
Views

获取 View 控件的 MultiView 控件的集合。

ViewState

获取状态信息的字典,这些信息使您可以在同一页的多个请求间保存和还原服务器控件的视图状态。

(继承自 Control)
ViewStateIgnoresCase

获取一个值,该值指示 StateBag 对象是否不区分大小写。

(继承自 Control)
ViewStateMode

获取或设置此控件的视图状态模式。

(继承自 Control)
Visible

获取或设置一个值,该值指示服务器控件是否作为 UI 呈现在页上。

(继承自 Control)

方法

AddedControl(Control, Int32)

在子控件添加到 Control 对象的 Controls 集合后调用。

(继承自 Control)
AddParsedSubObject(Object)

通知 MultiView 控件已分析了一个 XML 或 HTML 元素,并将该元素添加到 ViewCollection 控件的 MultiView 集合中。

ApplyStyleSheetSkin(Page)

将页样式表中定义的样式属性应用到控件。

(继承自 Control)
BeginRenderTracing(TextWriter, Object)

开始输出数据的设计时追踪。

(继承自 Control)
BuildProfileTree(String, Boolean)

收集有关服务器控件的信息并将该信息发送到 Trace 属性,在启用页的跟踪功能时将显示该属性。

(继承自 Control)
ClearCachedClientID()

将缓存的 ClientID 值设置为 null

(继承自 Control)
ClearChildControlState()

删除服务器控件的子控件的控件状态信息。

(继承自 Control)
ClearChildState()

删除服务器控件的所有子控件的视图状态和控件状态信息。

(继承自 Control)
ClearChildViewState()

删除服务器控件的所有子控件的视图状态信息。

(继承自 Control)
ClearEffectiveClientIDMode()

将当前控件实例和任何子控件的 ClientIDMode 属性设置为 Inherit

(继承自 Control)
CreateChildControls()

由 ASP.NET 页框架调用,以通知服务器控件在准备回发或呈现时使用基于撰写的实现来创建其所包含任何子控件。

(继承自 Control)
CreateControlCollection()

创建 ControlCollection 以保存 MultiView 控件的子控件。

DataBind()

将数据源绑定到调用的服务器控件及其所有子控件。

(继承自 Control)
DataBind(Boolean)

将数据源绑定到调用的服务器控件及其所有子控件,同时可以选择引发 DataBinding 事件。

(继承自 Control)
DataBindChildren()

将数据源绑定到服务器控件的子控件。

(继承自 Control)
Dispose()

使服务器控件得以在从内存中释放之前执行最后的清理操作。

(继承自 Control)
EndRenderTracing(TextWriter, Object)

结束输出数据的设计时追踪。

(继承自 Control)
EnsureChildControls()

确定服务器控件是否包含子控件。 如果不包含,则创建子控件。

(继承自 Control)
EnsureID()

为尚未分配标识符的控件创建标识符。

(继承自 Control)
Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
FindControl(String)

在当前的命名容器中搜索带指定 id 参数的服务器控件。

(继承自 Control)
FindControl(String, Int32)

使用指定的 idpathOffset 参数(该参数有助于搜索)中指定的整数在当前命名容器中搜索服务器控件。 不应重写此版本的 FindControl 方法。

(继承自 Control)
Focus()

为控件设置输入焦点。

(继承自 Control)
GetActiveView()

返回 View 控件的当前活动 MultiView 控件。

GetDesignModeState()

获取控件的设计时数据。

(继承自 Control)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetRouteUrl(Object)

获取与一组路由参数对应的 URL。

(继承自 Control)
GetRouteUrl(RouteValueDictionary)

获取与一组路由参数对应的 URL。

(继承自 Control)
GetRouteUrl(String, Object)

获取与一组路由参数以及某个路由名称对应的 URL。

(继承自 Control)
GetRouteUrl(String, RouteValueDictionary)

获取与一组路由参数以及某个路由名称对应的 URL。

(继承自 Control)
GetType()

获取当前实例的 Type

(继承自 Object)
GetUniqueIDRelativeTo(Control)

返回指定控件的 UniqueID 属性的前缀部分。

(继承自 Control)
HasControls()

确定服务器控件是否包含任何子控件。

(继承自 Control)
HasEvents()

返回一个值,该值指示是否为控件或任何子控件注册事件。

(继承自 Control)
IsLiteralContent()

确定服务器控件是否只包含文字内容。

(继承自 Control)
LoadControlState(Object)

加载 MultiView 控件的当前状态。

LoadViewState(Object)

从用 SaveViewState() 方法保存的上一个页面请求还原视图状态信息。

(继承自 Control)
MapPathSecure(String)

检索虚拟路径(绝对的或相对的)映射到的物理路径。

(继承自 Control)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
OnActiveViewChanged(EventArgs)

引发 ActiveViewChanged 控件的 MultiView 事件。

OnBubbleEvent(Object, EventArgs)

确定 MultiView 控件的事件是否传递给页的用户界面服务器控件层次结构。

OnDataBinding(EventArgs)

引发 DataBinding 事件。

(继承自 Control)
OnInit(EventArgs)

引发 Init 事件。

OnLoad(EventArgs)

引发 Load 事件。

(继承自 Control)
OnPreRender(EventArgs)

引发 PreRender 事件。

(继承自 Control)
OnUnload(EventArgs)

引发 Unload 事件。

(继承自 Control)
OpenFile(String)

获取用于读取文件的 Stream

(继承自 Control)
RaiseBubbleEvent(Object, EventArgs)

将所有事件源及其信息分配给控件的父级。

(继承自 Control)
RemovedControl(Control)

在将 View 控件从 Controls 控件的 MultiView 集合中移除后调用。

Render(HtmlTextWriter)

MultiView 控件内容写入指定的 HtmlTextWriter 对象,以便在客户端显示。

RenderChildren(HtmlTextWriter)

将服务器控件子级的内容输出到提供的 HtmlTextWriter 对象,该对象可写入要在客户端上呈现的内容。

(继承自 Control)
RenderControl(HtmlTextWriter)

将服务器控件内容输出到所提供的 HtmlTextWriter 对象,如果启用了跟踪,则还将存储有关该控件的跟踪信息。

(继承自 Control)
RenderControl(HtmlTextWriter, ControlAdapter)

使用提供的 HtmlTextWriter 对象将服务器控件内容输出到提供的 ControlAdapter 对象。

(继承自 Control)
ResolveAdapter()

获取负责呈现指定控件的控件适配器。

(继承自 Control)
ResolveClientUrl(String)

获取浏览器可以使用的 URL。

(继承自 Control)
ResolveUrl(String)

将 URL 转换为在请求客户端可用的 URL。

(继承自 Control)
SaveControlState()

保存 MultiView 控件的当前状态。

SaveViewState()

保存将页面回发到服务器之后发生的所有服务器控件视图状态更改。

(继承自 Control)
SetActiveView(View)

将指定的 View 控件设置为 MultiView 控件的活动视图。

SetDesignModeState(IDictionary)

为控件设置设计时数据。

(继承自 Control)
SetRenderMethodDelegate(RenderMethod)

分配事件处理程序委托,以将服务器控件及其内容呈现到父控件中。

(继承自 Control)
SetTraceData(Object, Object)

使用跟踪数据键和跟踪数据值,为呈现数据的设计时追踪设置跟踪数据。

(继承自 Control)
SetTraceData(Object, Object, Object)

使用跟踪对象、跟踪数据键和跟踪数据值,为呈现数据的设计时追踪设置跟踪数据。

(继承自 Control)
ToString()

返回表示当前对象的字符串。

(继承自 Object)
TrackViewState()

导致跟踪服务器控件的视图状态的更改,以便这些更改可以存储到服务器控件的 StateBag 对象中。 通过 ViewState 属性可访问此对象。

(继承自 Control)

事件

ActiveViewChanged

View 控件的活动 MultiView 控件在两次服务器发送间发生更改时发生。

DataBinding

当服务器控件绑定到数据源时发生。

(继承自 Control)
Disposed

当从内存释放服务器控件时发生,这是请求 ASP.NET 页时服务器控件生存期的最后阶段。

(继承自 Control)
Init

当服务器控件初始化时发生;初始化是控件生存期的第一步。

(继承自 Control)
Load

当服务器控件加载到 Page 对象中时发生。

(继承自 Control)
PreRender

在加载 Control 对象之后、呈现之前发生。

(继承自 Control)
Unload

当服务器控件从内存中卸载时发生。

(继承自 Control)

显式接口实现

IControlBuilderAccessor.ControlBuilder

有关此成员的说明,请参见 ControlBuilder

(继承自 Control)
IControlDesignerAccessor.GetDesignModeState()

有关此成员的说明,请参见 GetDesignModeState()

(继承自 Control)
IControlDesignerAccessor.SetDesignModeState(IDictionary)

有关此成员的说明,请参见 SetDesignModeState(IDictionary)

(继承自 Control)
IControlDesignerAccessor.SetOwnerControl(Control)

有关此成员的说明,请参见 SetOwnerControl(Control)

(继承自 Control)
IControlDesignerAccessor.UserData

有关此成员的说明,请参见 UserData

(继承自 Control)
IDataBindingsAccessor.DataBindings

有关此成员的说明,请参见 DataBindings

(继承自 Control)
IDataBindingsAccessor.HasDataBindings

有关此成员的说明,请参见 HasDataBindings

(继承自 Control)
IExpressionsAccessor.Expressions

有关此成员的说明,请参见 Expressions

(继承自 Control)
IExpressionsAccessor.HasExpressions

有关此成员的说明,请参见 HasExpressions

(继承自 Control)
IParserAccessor.AddParsedSubObject(Object)

有关此成员的说明,请参见 AddParsedSubObject(Object)

(继承自 Control)

扩展方法

FindDataSourceControl(Control)

返回与指定控件的数据控件关联的数据源。

FindFieldTemplate(Control, String)

返回指定控件的命名容器中指定列的字段模板。

FindMetaTable(Control)

返回包含数据控件的元表对象。

适用于

另请参阅