asp.net向导activestepchange下一步按钮更改验证组

时间:2014-10-27 12:08:08

标签: c# asp.net .net

我需要知道这是否可行,我有一个向导,当我进入第5步时,我需要从下一个按钮更改按钮,因为向导的完整步骤不显示步骤和我需要它来显示,所以我找到了一种方法来做事但我需要一个按钮在进入第5步时变为可见,但问题是它必须在activeStepChanged(我认为)上完成。

这是代码:

protected void wizard1_ActiveStepChanged ( object sender, EventArgs e ) {
    ((Button)(wizard1.FindControl("StepNavigationTemplate$btnNext"))).Visible = true;
    ((Button)(wizard1.FindControl("StepNavigationTemplate$btnFinish"))).Visible = false;
    switch(wizard1.ActiveStepIndex) {
        case 1:
            wizard1.MoveTo(WizardStep2);
            break;
        case 2:
            wizard1.MoveTo(WizardStep3);
            break;
        case 3:
            wizard1.MoveTo(WizardStep4);
            break;
        case 4:
            wizard1.MoveTo(WizardStep5);
            ((Button)(wizard1.FindControl("StartNavigationTemplateContainerID$btnNext"))).Visible = false;
            ((Button)(wizard1.FindControl("StartNavigationTemplateContainerID$btnFinish"))).Visible = true;
            break;
        case 5:
            wizard1.MoveTo(WizardStep6);
            break;
    }
}

这可能吗?因为当我运行代码时它表示该按钮为空,我尝试了其他类似的方法:

protected void wizard1_ActiveStepChanged ( object sender, EventArgs e ) {
    Button btnNext = (Button)wizard1.FindControl("btnNext");
    Button btnFinish = (Button)wizard1.FindControl("btnFinish");
    btnNext.Visible = true;
    btnFinish.Visible = false;
    switch(wizard1.ActiveStepIndex) {
        case 1:
            wizard1.MoveTo(WizardStep2);
            break;
        case 2:
            wizard1.MoveTo(WizardStep3);
            break;
        case 3:
            wizard1.MoveTo(WizardStep4);
            break;
        case 4:
            wizard1.MoveTo(WizardStep5);
            btnNext.Visible = false;
            btnFinish.Visible = true;
            break;
        case 5:
            wizard1.MoveTo(WizardStep6);
            break;
    }
}

但它总是返回我按钮为空,有没有办法捕获ActiveStepChanged上的按钮?如果没有,我还有什么其他选择让它起作用?

这里是按钮代码:

<StartNavigationTemplate>
    <asp:Button ID="StartNextButton" runat="server" CommandName="MoveNext" Text="SEGUINTE" CssClass="wizard-nav-buttons" ValidationGroup="valReg" CausesValidation="true" />
</StartNavigationTemplate>
<StepNavigationTemplate>
    <div style="display: table-cell;">
        <asp:Button ID="btnPrevious" runat="server" Text="ANTERIOR" CommandName="MovePrevious" CausesValidation="true" CssClass="wizard-nav-buttons prev" />
    </div>
    <div style="display: table-cell; padding-left: 10px;">
        <asp:Button ID="btnNext" runat="server" CommandName="MoveNext" Text="SEGUINTE" CausesValidation="true" CssClass="wizard-nav-buttons" />
    </div>
    <div style="display: table-cell; padding-left: 10px;">
        <asp:Button ID="btnFinish" runat="server" OnClick="wizard1_FinishButtonClick" Text="SUBMETER PROPOSTA" CssClass="wizard-nav-buttons submeterProposta" CausesValidation="true" Visible="false" />
    </div>
</StepNavigationTemplate>
<FinishNavigationTemplate></FinishNavigationTemplate>

到目前为止,谢谢你。

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,实际上非常简单,因为我在ActiveStepIndex被定义(预呈现)之前尝试调用按钮无法找到它(正常因为它甚至没有被创建),所以经过几次尝试和一天早上的搜索和测试,我试着把它放在开关中的一个案例之后就找到了,所以对于那些可能遇到这种困难的人来说,这里是功能代码:

protected void wizard1_ActiveStepChanged ( object sender, EventArgs e ) {
    Button btnNext , btnFinish;
    switch(wizard1.ActiveStepIndex) {
        case 1:
            btnNext = (Button)wizard1.FindControl("StepNavigationTemplateContainerID").FindControl("btnNext");
            btnFinish = (Button)wizard1.FindControl("StepNavigationTemplateContainerID").FindControl("btnFinish");
            btnNext.ValidationGroup = "valAutUniq";
            btnNext.Visible = true;
            btnFinish.Visible = false;
            wizard1.MoveTo(WizardStep2);
            break;
        case 2:
            btnNext = (Button)wizard1.FindControl("StepNavigationTemplateContainerID").FindControl("btnNext");
            btnFinish = (Button)wizard1.FindControl("StepNavigationTemplateContainerID").FindControl("btnFinish");
            btnNext.ValidationGroup = "valAutUniq";
            btnNext.Visible = true;
            btnFinish.Visible = false;
            wizard1.MoveTo(WizardStep3);
            break;
        case 3:
            btnNext = (Button)wizard1.FindControl("StepNavigationTemplateContainerID").FindControl("btnNext");
            btnFinish = (Button)wizard1.FindControl("StepNavigationTemplateContainerID").FindControl("btnFinish");
            btnNext.ValidationGroup = "valFormPag";
            btnNext.Visible = true;
            btnFinish.Visible = false;
            wizard1.MoveTo(WizardStep4);
            break;
        case 4:
            btnNext = (Button)wizard1.FindControl("StepNavigationTemplateContainerID").FindControl("btnNext");
            btnFinish = (Button)wizard1.FindControl("StepNavigationTemplateContainerID").FindControl("btnFinish");
            btnNext.ValidationGroup = null;
            btnNext.Visible = false;
            btnFinish.Visible = true;
            wizard1.MoveTo(WizardStep5);
            break;
    }
}