Wizard.AllowNavigationToStep(Int32) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
使用布林值來判斷 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 物件的索引。
傳回
如果傳入之索引參考已經存取的 WizardStepBase,且其 AllowReturn 屬性設定為 false
,則為 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 屬性。 如果傳入的索引參考WizardStepBase已存取的物件,且其 AllowReturn 屬性設定為 false
,則AllowNavigationToStep方法會false
傳回 ,否則會傳回 true
。