Radiobutton.Checked 不适用于组中的第一个按钮

发布于 2024-08-09 01:04:30 字数 239 浏览 2 评论 0原文

我检查了我的 ASP.NET 单选按钮组中的第一个单选按钮。由于某种原因,页面加载并且第一个按钮被自动检查,而不是我们将其设置为检查......它必须自然地检查自身,因为它是组中的第一个按钮。

但是,当我实际检查它是否在 if 语句中检查(以便我可以对其进行操作)时,它会返回 false,即使在页面呈现

myRadioButton.Checked 时确实进行了检查,最终结果为 false。不知道为什么。

I've got a check for the first radiobutton in my group of ASP.NET radiobuttons. For some reason, the page loads and that first button is automatically checked, not that we're setting it to be checked..it must naturally check itself since it's the first in the group.

However, when I actually check that it's checked in an if statement (so that I can act on it) it returns false even though it's checked for sure when the page renders

myRadioButton.Checked ends up with false. Not sure why.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁与争疯 2024-08-16 01:04:31

我的观点是,您在 Page_Load 期间设置按钮状态,并且忘记检查 IsPostBack 是否为 true/false。您的代码可能如下所示:

Page_Load(...) {
  SetFormState()
}    

当它应该如下所示时:

Page_Load(...) {
    if (!IsPostBack) {
      SetFormState()
    }
}

My dollars are that you're setting the button state during Page_Load and forgetting to check whether IsPostBack is true/false. Your code likely looks like this:

Page_Load(...) {
  SetFormState()
}    

When it should look like this:

Page_Load(...) {
    if (!IsPostBack) {
      SetFormState()
    }
}
伤痕我心 2024-08-16 01:04:30

最终成为一个逻辑问题。我在检查逻辑后进行了绑定。

ended up being a logic problem. I was binding after my check logic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文