在上一步中禁用控件

本文关键字:控件 一步 | 更新日期: 2023-09-27 17:51:10

如何禁用所有复选框或所有单选按钮在向导的上一步后,nextbuttonclick事件?

在上一步中禁用控件

ASPX:

<asp:Wizard ID="Wizard1" runat="server" 
        onnextbuttonclick="Wizard1_NextButtonClick">
        <WizardSteps>
            <asp:WizardStep ID="Step1" runat="server" Title="Step 1">
                <asp:RadioButton ID="RadioButton1" Text="Option 1" runat="server" />
                <asp:RadioButton ID="RadioButton2" Text="Option 2" runat="server" />
                <asp:RadioButton ID="RadioButton3" Text="Option 3" runat="server" />
            </asp:WizardStep>
            <asp:WizardStep ID="Step2" runat="server" Title="Step 2">
            </asp:WizardStep>
        </WizardSteps>
    </asp:Wizard>

代码:

protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
{
    if (Wizard1.ActiveStep == Step1)
    {
        IEnumerable<RadioButton> controls = FindControls<RadioButton>(Step1);
        controls.ToList().ForEach(c => c.Enabled = false);
    }
}
IEnumerable<T> FindControls<T>(Control parent) where T : Control
{
    foreach (Control c in parent.Controls)
    {
        if (c.GetType() == typeof(T)) yield return (T)c;
        foreach (var subControl in FindControls<T>(c))
            yield return subControl;
    }
}

好的,我检查过了,它不起作用,当step.allowreturn=false .