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 Form程式碼模型的詳細資訊,請參閱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 方法來定義使用中檢視。 如果屬性是空的 ActiveViewIndexMultiView ,控制項就不會將任何內容轉譯至用戶端。 如果作用中檢視設定為 View 控制項內不存在的 MultiViewArgumentOutOfRangeException 則會在執行時間引發 。

您可以以宣告方式或以程式設計方式定義使用中的檢視。 ActiveViewIndex當您定義 控制項時 MultiView ,以宣告方式設定 屬性,會在第一次呼叫控制項時 MultiView ,將 View 設定為使用中檢視轉譯至用戶端。 下列程式碼範例示範如何以宣告方式設定 ActiveViewIndex 屬性。

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

ActiveViewIndex以程式設計方式設定 屬性或呼叫 SetActiveView 方法,可讓應用程式根據使用者的身分識別或喜好設定等準則,判斷 View 在執行時間轉譯給用戶端的控制項。

若要允許使用者在控制項內的控制項之間 View 流覽,您可以將 或 Button 控制項新增 LinkButton 至每個 ViewMultiView 控制項。 若要利用 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 識別碼變更控制項中作用 ViewMultiView 控制項相關聯的命令名稱。此欄位是唯讀的。

SwitchViewByIndexCommandName

根據指定的 View 索引而定,表示與變更 MultiView 控制項中現用 View 控制項關聯的命令名稱。 此欄位為唯讀。

屬性

ActiveViewIndex

取得或設定 View 控制項中現用 MultiView 控制項的索引。

Adapter

針對控制項取得瀏覽器的特定配置器。

(繼承來源 Control)
AppRelativeTemplateSourceDirectory

取得或設定包含了此控制項之 PageUserControl 物件的相對應用程式虛擬目錄。

(繼承來源 Control)
BindingContainer

取得包含了此控制項之資料繫結的控制項。

(繼承來源 Control)
ChildControlsCreated

取得值,指出是否已經建立伺服器控制項的子控制項。

(繼承來源 Control)
ClientID

取得 ASP.NET 所產生之 HTML 標記的控制項識別碼。

(繼承來源 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

取得控制項事件處理常式委派 (Delegate) 的清單。 這個屬性是唯讀的。

(繼承來源 Control)
HasChildViewState

取得值,指出目前伺服器控制項的子控制項是否有任何已儲存的檢視狀態設定。

(繼承來源 Control)
ID

取得或設定指派給伺服器控制項的程式設計識別項。

(繼承來源 Control)
IdSeparator

取得用來分隔控制項識別項的字元。

(繼承來源 Control)
IsChildControlStateCleared

取得值,指出這個控制項中所包含的控制項是否有控制項狀態。

(繼承來源 Control)
IsTrackingViewState

取得值,指出伺服器控制項是否正在儲存檢視狀態的變更。

(繼承來源 Control)
IsViewStateEnabled

取得值,指出這個控制項是否已啟用檢視狀態。

(繼承來源 Control)
LoadViewStateByID

取得值,指出控制項是否依 ID (而不是索引) 參與載入其檢視狀態。

(繼承來源 Control)
NamingContainer

取得伺服器控制項命名容器的參考,其建立唯一命名空間,在具有相同 ID 屬性值的伺服器控制項之間作區別。

(繼承來源 Control)
Page

取得含有伺服器控制項的 Page 執行個體的參考。

(繼承來源 Control)
Parent

在網頁控制階層架構中取得伺服器控制項之父控制項的參考。

(繼承來源 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)

使用指定的 id 和有助於搜尋之 pathOffset 參數中所指定的整數,在目前的命名容器中搜尋伺服器控制項。 您不應該覆寫這個版本的 FindControl 方法。

(繼承來源 Control)
Focus()

設定控制項的輸入焦點。

(繼承來源 Control)
GetActiveView()

傳回 View 控制項中目前現用 MultiView 控制項。

GetDesignModeState()

取得控制項的設計階段資料。

(繼承來源 Control)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetRouteUrl(Object)

取得會對應於一組路由參數的 URL。

(繼承來源 Control)
GetRouteUrl(RouteValueDictionary)

取得會對應於一組路由參數的 URL。

(繼承來源 Control)
GetRouteUrl(String, Object)

取得 URL,此 URL 對應於一組路由參數及一個路由名稱。

(繼承來源 Control)
GetRouteUrl(String, RouteValueDictionary)

取得 URL,此 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 控制項的事件是否要傳遞至頁面的 UI 伺服器控制項階層架構中。

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()

導致對伺服器控制項的檢視狀態變更的追蹤 (Tracking),以便它們能夠儲存於伺服器控制項的 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)

傳回包含資料控制項的中繼資料表物件。

適用於

另請參閱