使用英语阅读

通过


Wizard.ActiveStepIndex 属性

定义

获取或设置当前 WizardStepBase 对象的索引。

C#
[System.Web.UI.Themeable(false)]
public virtual int ActiveStepIndex { get; set; }

属性值

当前显示在 WizardStepBase 控件中的 Wizard 的索引。

属性

例外

所选值大于 WizardSteps 集合中定义的向导步骤的数量。

示例

下面的代码示例演示如何使用 ActiveStepIndex 属性设置 ActiveStep 控件的 Wizard 属性。 如果 的CheckBox1.Checkedtrue值为 ,则 ActiveStep 属性设置为 Wizard1.Step3;否则, ActiveStep 属性设置为 Wizard1.Step2

ASP.NET (C#)
<%@ 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 OnActiveStepChanged(object sender, EventArgs e)
  {
    // If the ActiveStep is changing to Step2, check to see whether the 
    // CheckBox1 CheckBox is selected.  If it is, skip to the Step2 step.
    if (Wizard1.ActiveStepIndex == Wizard1.WizardSteps.IndexOf(this.WizardStep2))
    {
      if (this.CheckBox1.Checked)
      {
        Wizard1.ActiveStepIndex = Wizard1.WizardSteps.IndexOf(this.WizardStep3);
      }
    }
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
      <form id="form1" runat="server">
        <asp:Wizard id="Wizard1" 
          runat="server"
          OnActiveStepChanged="OnActiveStepChanged">
          <WizardSteps>
            <asp:WizardStep id="WizardStep1" 
              title="Step 1" 
              runat="server">
              <asp:CheckBox id="CheckBox1" 
                runat="Server" 
                text="Select this check box to skip Step 2." />
                You are currently on Step 1.
            </asp:WizardStep>
            <asp:WizardStep id="WizardStep2" 
              title="Step 2" 
              runat="server">
              You are currently on Step 2.
            </asp:WizardStep>
            <asp:WizardStep id="WizardStep3" 
              runat="server" 
              title="Step 3">
              You are currently on Step 3.
            </asp:WizardStep>
          </WizardSteps>
          <HeaderTemplate>
            <b>ActiveStepIndex Example</b>
          </HeaderTemplate>
        </asp:Wizard>
      </form>
  </body>
</html>

注解

属性ActiveStepIndex提供当前显示在 控件中的对象的从零开始的Wizard索引WizardStepBase。 你可以以编程方式设置 ActiveStepIndex 属性,以控制在运行时向用户显示哪个步骤。

备注

如果使用的是 Microsoft Visual Studio 2005,请注意, ActiveStepIndex 将保留在“源”视图中。 如果在“设计”视图中通过单击边栏按钮更改 WizardSteps 属性,然后运行页面,则控件的第一步 Wizard 可能不会显示,因为 ActiveStepIndex 可能指向不同的步骤。

如果将 的值 ActiveStepIndex 设置为 -1 以支持默认情况下不执行任何步骤的向导,则会发生以下行为:

  • 如果以声明方式将 设置为 ActiveStepIndex -1 或将其设置为 -1 作为默认值,控件将始终尝试呈现向导中的第一步。

  • 如果以 ActiveStepIndex 编程方式设置为 -1,则控件将不会呈现。

无法通过主题或样式表主题设置此属性。 有关详细信息,请参阅 ThemeableAttributeASP.NET 主题和皮肤

适用于

产品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

另请参阅