[英]Advancing wizard from code-behind in ASP.NET
I have a wizard on my page, and it has a "Next" button. 我的页面上有一个向导,它有一个“下一步”按钮。 I would like to "click" that button from code-behind when clicking another button on the page. 当我点击页面上的另一个按钮时,我想从代码隐藏中“点击”该按钮。
More specifically: There is a button on my page that has two functions: after clicking it, in the postback, it either sets up the code required to reload the page and display a popup, or it advances the wizard if it deems the popup unnecessary. 更具体地说:我的页面上有一个按钮,它有两个功能:点击它后,在回发中,它设置重新加载页面所需的代码并显示一个弹出窗口,或者如果它认为不需要弹出窗口则向前推进向导。 In case the popup is shown, it contains a button to advance the wizard. 如果显示弹出窗口,它包含一个按钮以推进向导。
Some code snippets: 一些代码片段:
Wizard init: 向导初始化:
<asp:Wizard ID="RegistrationWizard" meta:resourcekey="RegistrationWizard"
runat="server" OnFinishButtonClick="RegistrationWizard_FinishButtonClick"
OnActiveStepChanged="RegistrationWizard_ActiveStepChanged"
OnNextButtonClick="RegistrationWizard_NextButtonClick">
Button to show popup or advance: 按钮显示弹出或前进:
<asp:Button ID="btnModulesNextPostBack" runat="server" CssClass="submit rounded"
meta:resourcekey="btnNext" onclick="btnModulesNextPostBack_Click" />
Button to advance wizard: 按钮推进向导:
<asp:Button ID="btnModulesStepNext" runat="server" CssClass="submit rounded"
meta:resourcekey="btnNext" CommandName="MoveNext" />
Code-behind of the btnModulesNextPostBack_Click method: btnModulesNextPostBack_Click方法的代码隐藏:
protected void btnModulesNextPostBack_Click(object sender, EventArgs e)
{
showPopup = false; // if set to true: will open popup in postback
// ... code to determine if popup should be shown
if (!showNewsletterPopup)
{
// TODO! trigger "move to next step in wizard"
}
}
I don't know what to place in the TODO line, because I want to be sure that all other methods related to the wizard get called in the same order as usual too (RegistrationWizard_NextButtonClick and RegistrationWizard_ActiveStepChanged and maybe others the wizard code calls internally). 我不知道在TODO行中放置什么,因为我想确保与向导相关的所有其他方法也按照通常的顺序调用(RegistrationWizard_NextButtonClick和RegistrationWizard_ActiveStepChanged以及向导代码在内部调用的其他方法)。
How can I do this? 我怎样才能做到这一点? (.net version is 4.0) (.net版本是4.0)
You should be able to just increment the ActiveStepIndex
: 您应该只能增加ActiveStepIndex
:
Wizard1.ActiveStepIndex++;
You could also use the MoveTo
method: 您还可以使用MoveTo
方法:
Wizard1.MoveTo(WizardStep1);
Lastly, if you want to navigate the wizard forward and backwards, you can use the NextButtonClick
and PreviousButtonClick
: 最后,如果要向前和向后导航向导,可以使用NextButtonClick
和PreviousButtonClick
:
protected void wzServiceOrder_PreviousButtonClicked(object sender, WizardNavigationEventArgs e)
{
//decrement the active step index
wzServiceOrder.ActiveStepIndex--;
//move the wizard to the active step
wzServiceOrder.MoveTo(wzServiceOrder.ActiveStep);
}
/// <summary>
/// Handles wzServiceOrder OnNextButtonClick event.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void wzServiceOrder_NextButtonClicked(object sender, WizardNavigationEventArgs e)
{
//increment the active step index
Wizard1.ActiveStepIndex++;
//move the wizard to the active step
Wizard1.MoveTo(Wizard1.ActiveStep);
if (e.NextStepIndex > Wizard1.WizardSteps.IndexOf(WizardStep1))
{
if (!contactsExist)
{
Popop1.Show();
e.Cancel = true;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.