MultiView.SwitchViewByIndexCommandName Champ

Définition

Représente le nom de commande associé à la modification du contrôle View actif dans un contrôle MultiView en fonction d'un index View spécifié. Ce champ est en lecture seule.

public: static initonly System::String ^ SwitchViewByIndexCommandName;
public static readonly string SwitchViewByIndexCommandName;
 staticval mutable SwitchViewByIndexCommandName : string
Public Shared ReadOnly SwitchViewByIndexCommandName As String 

Valeur de champ

Exemples

L’exemple de code suivant montre comment utiliser un MultiView contrôle pour créer une enquête de base. Chaque View contrôle est une question d’enquête distincte. Les PreviousViewCommandName champs et NextViewCommandName sont utilisés pour fournir une navigation automatique entre les contrôles précédent et suivant View de l’enquête. Si l’utilisateur clique sur le bouton Retake Survey dans le dernier View de l’enquête, le SwitchViewByIndexCommandName champ est utilisé avec un argument de commande 0 pour rediriger l’utilisateur vers le premier View de l’enquête.

Notes

L’exemple de code suivant utilise le modèle de code à fichier unique et peut ne pas fonctionner correctement s’il est copié directement dans un fichier code-behind. Cet exemple de code doit être copié dans un fichier texte vide qui a une extension .aspx. Pour plus d’informations sur le modèle de code Web Forms, consultez ASP.NET Web Forms Modèle de code de page.

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

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    void Page4SaveButton_Click(Object sender, System.EventArgs e)
    {
      // 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;

    }
    
  </script>
  
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
  <title>MultiView.SwitchViewByIndexCommandName Example</title>
</head>
<body>
    <form id="Form1" runat="Server">
        
      <h3>MultiView.SwitchViewByIndexCommandName 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"
              CommandName="NextView"
              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"
              CommandName="PrevView"
              Height="25"
              Width="70"
              runat= "Server">
            </asp:Button> 

            <asp:Button id="Page2Next"
              Text = "Next"
              CommandName="NextView"
              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" 
              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"
              CommandName="PrevView"
              Height="25"
              Width="70"
              runat="Server">
            </asp:Button> 

            <asp:Button id="Page3Next"
              Text = "Next"
              CommandName="NextView"
              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="Page4SaveButton_Click"
            Height="25"
            Width="110"
            runat="Server">
          </asp:Button>
                
          <asp:Button id="Page4Restart"
            Text = "Retake Survey"
            commandname="SwitchViewByIndex"
            commandargument="0"
            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">
<script runat="server">

    Sub Page4SaveButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        
      ' 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

    End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
  <title>MultiView.SwitchViewByIndexCommandName Example</title>
</head>
<body>
    <form id="Form1" runat="Server">
        
      <h3>MultiView.SwitchViewByIndexCommandName 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"
              CommandName="NextView"
              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"
              CommandName="PrevView"
              Height="25"
              Width="70"
              runat= "Server">
            </asp:Button> 

            <asp:Button id="Page2Next"
              Text = "Next"
              CommandName="NextView"
              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" 
              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"
              CommandName="PrevView"
              Height="25"
              Width="70"
              runat="Server">
            </asp:Button> 

            <asp:Button id="Page3Next"
              Text = "Next"
              CommandName="NextView"
              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="Page4SaveButton_Click"
            Height="25"
            Width="110"
            runat="Server">
          </asp:Button>
                
          <asp:Button id="Page4Restart"
            Text = "Retake Survey"
            commandname="SwitchViewByIndex"
            commandargument="0"
            Height="25"
            Width="110"
            runat= "Server">
          </asp:Button>                    
                    
        </asp:View>  
       
      </asp:MultiView>
        
    </asp:Panel> 

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

Remarques

Utilisez le SwitchViewByIndexCommandName champ pour représenter le nom de la commande « SwitchViewByIndex ».

Vous pouvez utiliser la valeur de ce champ pour tirer parti de la MultiView mise à jour automatique du contrôle actif View . Par exemple, si un View contrôle contient un Button contrôle qui accède au premier View en cas de clic, vous pouvez définir la CommandName propriété sur la valeur du SwitchViewByIndexCommandName champ, qui est « SwitchViewByIndex ». Définissez la CommandArgument propriété sur l’index du premier View dans le MultiView contrôle, qui est 0. MultiView Le contrôle définit automatiquement la ActiveViewIndex propriété sur 0 lorsque vous cliquez sur le bouton.

S’applique à

Voir aussi