在 C# 的构造函数中确定选定的单选按钮
您好,
我有这个构造函数:
public EmployeeCategorizationControl()
{
}
和许多单选按钮:
<asp:RadioButtonList ID="selectedYesNoQuestionBlock1" runat="server" RepeatDirection="Horizontal"
OnSelectedIndexChanged="Question1GotAnswered" AutoPostBack="true">
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
<asp:ListItem Text="No" Value="0"></asp:ListItem>
</asp:RadioButtonList>
<asp:RadioButtonList ID="selectedYesNoQuestionBlock2" runat="server" RepeatDirection="Horizontal"
AutoPostBack="true" OnSelectedIndexChanged="Question2GotAnswered">
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
<asp:ListItem Text="No" Value="0"></asp:ListItem>
</asp:RadioButtonList>
在我的构造函数中,如何确定选择了哪个单选按钮?
提前致谢!
Hello,
I have this constructor:
public EmployeeCategorizationControl()
{
}
and many radio buttons:
<asp:RadioButtonList ID="selectedYesNoQuestionBlock1" runat="server" RepeatDirection="Horizontal"
OnSelectedIndexChanged="Question1GotAnswered" AutoPostBack="true">
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
<asp:ListItem Text="No" Value="0"></asp:ListItem>
</asp:RadioButtonList>
<asp:RadioButtonList ID="selectedYesNoQuestionBlock2" runat="server" RepeatDirection="Horizontal"
AutoPostBack="true" OnSelectedIndexChanged="Question2GotAnswered">
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
<asp:ListItem Text="No" Value="0"></asp:ListItem>
</asp:RadioButtonList>
In my constructor, how can I determine which radio button is selected?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 asp.net,与构造函数中的控件交互并不是一个好主意,因为
With asp.net, interacting with controls in the constructor is not a good idea because of the way the page life cycle works. You might want to glance through the page life cycle msdn page and consider
Load
orInit
event instead.您不能:
请求< /code>
在构建页面实例之后之后才可用。您必须稍后在页面生命周期。
在
Load
之前(例如在初始化期间),您只能通过请求访问选择:Load
将请求值映射到您的控制对象 - 从那时起您可以访问直接通过控件获取值:You can't: the
Request
isn't available until the after constructing the page instance. You have to do it at a later point in the page lifecycle.Before
Load
(during initialization for example) you can only access the selection through the request:Load
maps the request values to your control objects - from that point on you can access the values directly through the controls: