Search code examples
c#asp.netradio-buttonradiobuttonlist

Determine Selected Radiobutton in Constructor in C#


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!


Solution

  • 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 or Init event instead.