Compartir a través de


Wizard.AllowNavigationToStep(Int32) Método

Definición

Utiliza un valor booleano para determinar si la propiedad ActiveStep se puede establecer en el objeto WizardStepBase que corresponde al índice que se pasa.

protected:
 virtual bool AllowNavigationToStep(int index);
protected virtual bool AllowNavigationToStep (int index);
abstract member AllowNavigationToStep : int -> bool
override this.AllowNavigationToStep : int -> bool
Protected Overridable Function AllowNavigationToStep (index As Integer) As Boolean

Parámetros

index
Int32

Índice del objeto WizardStepBase que se va a comprobar.

Devoluciones

Boolean

Es false si el índice pasado hace referencia a un objeto WizardStepBase al que ya se ha tenido acceso y su propiedad AllowReturn se establece en false; en caso contrario, es true.

Ejemplos

En el ejemplo de código siguiente se muestra cómo crear una clase derivada denominada CustomWizard e invalidar el OnSideBarButtonClick método . Cuando se hace clic en un botón en el área de la barra lateral del CustomWizard control, AllowNavigationToStep se llama al método para determinar si se puede acceder al paso seleccionado. A continuación, se escribe un mensaje en la página web contenedora que informa al usuario de lo que ha ocurrido.

<%@ 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">

  // This custom wizard control defines the OnSideBarButtonClick method
  // that uses the AllowNavigationToStep method to determine whether the
  // value passed in can be used to set the ActiveStepIndex property.    
  class CustomWizard : Wizard
  {    
    override protected void OnSideBarButtonClick(WizardNavigationEventArgs e)
    {
      base.OnSideBarButtonClick(e);
      if (AllowNavigationToStep(e.NextStepIndex))
      {
        this.Page.Response.Write("AllowNavigationToStep() returned true, moving to Step" 
          + (e.NextStepIndex + 1).ToString() + ".");
        this.ActiveStepIndex = e.NextStepIndex;
      }
      else
      {
        this.Page.Response.Write("AllowNavigationToStep() returned false for Step" 
          + (e.NextStepIndex + 1).ToString() + ", moving to Step2.");
        this.ActiveStepIndex = 1;
      }
    }         
  }
  
  // Add the custom wizard control to the page.
  void Page_Load(object sender, EventArgs e) 
  {
      CustomWizard WizardControl = new CustomWizard();
      WizardControl.ID = "WizardControl";
      
      // Create some steps for the custom wizard.
      for (int i = 0; i <= 5; i++)
      {
        WizardStep newStep = new WizardStep();
        newStep.ID = "Step" + (i + 1).ToString();
        // Set AllowReturn to false for some of the steps.        
        if ((i % 2) == 0)
        {
          newStep.AllowReturn = false;
        }
        
        // Add each step to the custom wizard.
        WizardControl.WizardSteps.Add(newStep);
      }
            
      // Display the wizard on the page.
      PlaceHolder1.Controls.Add(WizardControl);
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>AllowNavigationToStep Example</title>
</head>
<body>
    <form id="Form1" runat="server">
      <h3>AllowNavigationToStep Example</h3>
      <asp:PlaceHolder id="PlaceHolder1" 
        runat="server" />
    </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">

  ' This custom wizard control defines the OnSideBarButtonClick method
  ' that uses the AllowNavigationToStep method to determine whether the
  ' value passed in can be used to set the ActiveStepIndex property.    
  Class CustomWizard
    Inherits Wizard
  
    Protected Overloads Sub OnSideBarButtonClick(ByVal sender As Object, _
      ByVal e As WizardNavigationEventArgs) Handles Me.SideBarButtonClick

      If AllowNavigationToStep(e.NextStepIndex) Then
        
        Me.Page.Response.Write("AllowNavigationToStep() returned true, moving to Step" & _
           (e.NextStepIndex + 1).ToString() & ".")
        Me.ActiveStepIndex = e.NextStepIndex
        
      Else
        
        Me.Page.Response.Write("AllowNavigationToStep() returned false for Step" & _
           (e.NextStepIndex + 1).ToString() & ", moving to Step2.")
        Me.ActiveStepIndex = 1
        
      End If
    End Sub
  End Class
  
  ' Add the custom wizard control to the page.
  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    Dim WizardControl As New CustomWizard()
    WizardControl.ID = "WizardControl"
      
    ' Create some steps for the custom wizard.
    For i As Integer = 0 To 5
      Dim newStep As New WizardStep()
      newStep.ID = "Step" & (i + 1).ToString()
      ' Set AllowReturn to false for some of the steps.        
      If ((i Mod 2) = 0) Then
        newStep.AllowReturn = False
      End If
        
      ' Add each step to the custom wizard.
      WizardControl.WizardSteps.Add(newStep)
    Next
      
    ' Display the wizard on the page.
    PlaceHolder1.Controls.Add(WizardControl)
    
  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>AllowNavigationToStep Example</title>
</head>
<body>
    <form id="Form1" runat="server">
      <h3>AllowNavigationToStep Example</h3>
      <asp:PlaceHolder id="PlaceHolder1" 
        runat="server" />
    </form>
  </body>
</html>

Comentarios

Solo AllowNavigationToStep se puede acceder al método desde una clase derivada debido a su protected modificador. En una clase derivada, puede usar el AllowNavigationToStep método para determinar si el índice que se pasa se puede usar para establecer la ActiveStepIndex propiedad . El AllowNavigationToStep método devolverá false si el índice que se pasa hace referencia a un WizardStepBase objeto al que ya se ha accedido y tiene su AllowReturn propiedad establecida falseen ; de lo contrario, devolverá true.

Se aplica a

Consulte también