如何在步骤0禁用向导控制的下一步按钮?

时间:2014-03-13 15:25:49

标签: c# asp.net

我有一个向导控件,我第一次想要禁用它的下一个按钮。我在同一页面上有另一个按钮,当用户点击该按钮时,它将启用“下一步”按钮。一开始它将被禁用。

 <asp:Wizard ID="Wizard1" Runat="server" ActiveStepIndex="0" DisplaySideBar="False">
                         <StartNavigationTemplate>
                            <asp:Button ID="StepNextButton" runat="server" CommandName="MoveNext" Text="Next" />
                        </StartNavigationTemplate>
                        <FinishNavigationTemplate>
                            <asp:Button ID="FinishButton" runat="server" CommandName="MoveComplete" Text="Finish" />
                        </FinishNavigationTemplate>
                            <WizardSteps>
                            <asp:WizardStep ID="WizardStep1" Runat="server" Title="IP Configuration">

                            </asp:WizardStep>
                            <asp:WizardStep ID="WizardStep2" Runat="server" Title="Register">

                            </asp:WizardStep>
                        </WizardSteps>
                        </asp:Wizard>     

3 个答案:

答案 0 :(得分:1)

首先,您尚未将向导转换为模板。你首先将stepnavigation转换为模板,然后使用findcontrol来获取你想要的按钮并用.Enabled

以编程方式更改它。
 <asp:Wizard ID="Wizard1" Runat="server" ActiveStepIndex="0" DisplaySideBar="False">
                     <StartNavigationTemplate>
                        <asp:Button ID="StepNextButton" runat="server" CommandName="MoveNext" Text="Next" />
                    </StartNavigationTemplate>
                    <FinishNavigationTemplate>
                        <asp:Button ID="FinishButton" runat="server" CommandName="MoveComplete" Text="Finish" />
                    </FinishNavigationTemplate>
                        <StepNavigationTemplate>
                            <asp:Button ID="StepPreviousButton" runat="server" CausesValidation="False" 
                                CommandName="MovePrevious" Text="Previous" />
                            <asp:Button ID="StepNextButton" runat="server" CommandName="MoveNext" 
                                Text="Next" />
                     </StepNavigationTemplate>
                        <WizardSteps>
                        <asp:WizardStep ID="WizardStep1" Runat="server" Title="IP Configuration">

                        </asp:WizardStep>
                        <asp:WizardStep ID="WizardStep2" Runat="server" Title="Register">

                        </asp:WizardStep>
                    </WizardSteps>
                    </asp:Wizard> 


    protected void Page_Load(object sender, EventArgs e)
    {
        Button nextButton = ((Button)Wizard1.FindControl("StartNavigationTemplateContainerID").FindControl("StepNextButton"));
        nextButton.Enabled = false;
    }

答案 1 :(得分:0)

我尝试了几种方法来完成这项任务。但似乎没有一个真的有效。就像使用template.findcontrol(&#34; ...或使用css进行修改。它们都没有对我有用。所以我在这里尝试的是不要让用户进入下一页,除非他们符合网页的所有标准需要。假设我的密码为空的文本框。if (string.IsNullOrWhiteSpace(txtPasskey.Text)) 用户点击下一个按钮。除非验证完成,否则不会移至下一页。

protected void NextButton_Click(object sender, WizardNavigationEventArgs e)
{
    cmdCancel.Visible = true;
    VerifyPassword();
    try
    {
        if (lblPasskeyInformation.Text[0] == 'I' || lblPasskeyInformation.Text[0] == 'P')
        {
            e.Cancel = true;
            return;
        }
    }
    catch (Exception ex)
    {
        lblPasskeyInformation.Text = "You are not verified yet. Please enter the passkey.";
    }

}

你不需要尝试捕获。你只需要放置

 protected void NextButton_Click(object sender, WizardNavigationEventArgs e)
{
 e.Cancel = true;
            return;
}

干杯!

答案 2 :(得分:-1)

没有使用模板。

Button previousButton = Wizard1.WizardSteps[6]           // enter the correct index for WizardSteps
     .FindControl("StepNavigationTemplateContainerID")   // You get the button
     .FindControl("StepPreviousButton") as Button;       // This gives previous button.