【问题标题】:C#: How do I check the value of a field before Wizard's next step? (NextButtonClick)C#:如何在向导下一步之前检查字段的值? (下一个按钮单击)
【发布时间】:2015-02-21 01:22:07
【问题描述】:

当用户在向导的第一步之后单击“继续”时,我想检查 MyRadioBtn 的值(选定索引)是否为 1。如果不是,则打开一个面板,不要继续执行向导的第 2 步。

我遇到的问题是“MyRadioBtn.SelectedIndex”条件永远不会返回值 1。

前端:

<asp:RadioButtonList ID="MyRadioBtn" runat="server" AutoPostBack="True">
     <asp:ListItem Value="0">No</asp:ListItem>
     <asp:ListItem Value="1">Yes</asp:ListItem>
</asp:RadioButtonList>

代码隐藏:

protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
{
    if (Wizard1.ActiveStepIndex == 0)
    {
        if (MyRadioBtn.SelectedIndex == 1)
        {
            //Stop the user from moving on to step 2
            e.Cancel = true;
            //Show the user a panel
            WarningPanel.Visible = true;
        }
        else {
           //Continue to STEP 2
        }

    }
}

【问题讨论】:

  • 您是否验证了回发是否是使用网络工具触发的?

标签: c# asp.net validation radio-button radiobuttonlist


【解决方案1】:

您是否需要在用户从 de DropDownList 中选择一个项目后触发 postbkack?如果不是,请将AutoPostBack="True" 更改为AutoPostBack="False"

【讨论】:

  • 就是这样。我错过了未设置 AutoPostBack 值的事实(因此始终为“假”)。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-11-29
  • 2021-02-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-04
相关资源
最近更新 更多