Campo MultiView.SwitchViewByIndexCommandName
Aggiornamento: novembre 2007
Spazio dei nomi: System.Web.UI.WebControlsAssembly: System.Web (in System.Web.dll)
Utilizzare il campo SwitchViewByIndexCommandName per rappresentare il nome di comando "SwitchViewByIndex".
È possibile utilizzare il valore di questo campo per sfruttare la funzionalità di aggiornamento automatico del controllo View attivo fornita dal controllo MultiView. Se ad esempio un controllo View contiene un controllo Button che, quando viene scelto, si sposta sul primo controllo View, è possibile impostare la proprietà CommandName sul valore del campo SwitchViewByIndexCommandName, ovvero su "SwitchViewByIndex". Impostare la proprietà CommandArgument sull'indice del primo controllo View nel controllo MultiView, ovvero su 0. In questo modo, quando viene scelto il pulsante, il controllo MultiView imposta automaticamente la proprietà ActiveViewIndex su 0.
Nell'esempio di codice riportato di seguito viene illustrato come utilizzare un controllo MultiView per creare una verifica di base. Ogni controllo View è una domanda di verifica separata. I campi PreviousViewCommandName e NextViewCommandName vengono utilizzati per lo spostamento automatico tra i controlli View precedente e successivo nella verifica. Se l'utente sceglie il pulsante Retake Survey nell'ultimo controllo View della verifica, viene utilizzato il campo SwitchViewByIndexCommandName insieme a un argomento di comando 0 per reindirizzare l'utente al primo controllo View della verifica.
Nota: |
|---|
Ll'esempio di codice riportato di seguito utilizza il modello di codice a file singolo e potrebbe non funzionare in modo corretto se venisse copiato direttamente in un file code-behind. È necessario copiare l'esempio di codice in un file di testo vuoto con estensione ASPX. Per ulteriori informazioni sul modello di codice dei Web Form, vedere Modello di codice di pagine Web ASP.NET. |
<%@ 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>
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition , Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
.NET Framework e .NET Compact Framework non supportano tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.
Nota: