Wizard.AllowNavigationToStep(Int32) 方法

定义

使用一个布尔值来确定 ActiveStep 属性是否可以设置为与传入的索引对应的 WizardStepBase 对象。

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

参数

index
Int32

被检查的 WizardStepBase 对象的索引。

返回

Boolean

如果传入的索引引用已经被访问过而且 WizardStepBase 属性设置为 falseAllowReturn,则为 false;否则为 true

示例

下面的代码示例演示如何创建一 CustomWizard 个名为和重写该方法的 OnSideBarButtonClick 派生类。 单击控件边栏区域 CustomWizard 上的按钮时, AllowNavigationToStep 将调用该方法以确定是否可以访问所选步骤。 然后将消息写入包含网页,告知用户所发生的情况。

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

注解

AllowNavigationToStep仅由于派生类的protected修饰符,才能从派生类访问该方法。 在派生类中,可以使用 AllowNavigationToStep 该方法来确定传入的索引是否可用于设置 ActiveStepIndex 属性。 AllowNavigationToStep false如果传入的索引引用WizardStepBase已访问且其AllowReturn属性设置为 false;否则,该方法将返回true

适用于

另请参阅