从ASP.NET中的代码隐藏推进向导

Tom*_*tor 2 asp.net

我的页面上有一个向导,它有一个"下一步"按钮.当我点击页面上的另一个按钮时,我想从代码隐藏中"点击"该按钮.

更具体地说:我的页面上有一个按钮,它有两个功能:点击它后,在回发中,它设置重新加载页面所需的代码并显示一个弹出窗口,或者如果它认为不需要弹出窗口则向前推进向导.如果显示弹出窗口,它包含一个按钮以推进向导.

一些代码片段:

向导初始化:

<asp:Wizard ID="RegistrationWizard" meta:resourcekey="RegistrationWizard"
    runat="server" OnFinishButtonClick="RegistrationWizard_FinishButtonClick" 
    OnActiveStepChanged="RegistrationWizard_ActiveStepChanged" 
    OnNextButtonClick="RegistrationWizard_NextButtonClick">
Run Code Online (Sandbox Code Playgroud)

按钮显示弹出或前进:

<asp:Button ID="btnModulesNextPostBack" runat="server" CssClass="submit rounded"
    meta:resourcekey="btnNext" onclick="btnModulesNextPostBack_Click" />
Run Code Online (Sandbox Code Playgroud)

按钮推进向导:

<asp:Button ID="btnModulesStepNext" runat="server" CssClass="submit rounded" 
    meta:resourcekey="btnNext" CommandName="MoveNext" />
Run Code Online (Sandbox Code Playgroud)

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"
    }
}
Run Code Online (Sandbox Code Playgroud)

我不知道在TODO行中放置什么,因为我想确保与向导相关的所有其他方法也按照通常的顺序调用(RegistrationWizard_NextButtonClick和RegistrationWizard_ActiveStepChanged以及向导代码在内部调用的其他方法).

我怎样才能做到这一点?(.net版本是4.0)

Jam*_*son 8

你应该能够增加ActiveStepIndex:

Wizard1.ActiveStepIndex++;
Run Code Online (Sandbox Code Playgroud)

您也可以使用以下MoveTo方法:

Wizard1.MoveTo(WizardStep1);
Run Code Online (Sandbox Code Playgroud)

最后,如果要向前和向后导航向导,可以使用NextButtonClickPreviousButtonClick:

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;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)