In the process of dynamically creating radio buttons in a user control based on values from a config file, there seems to be an issue with how the radio button objects are being generated. The code snippet provided below showcases this scenario:
<ul class="form_items">
<%
int i=1;
string displayText = String.Empty;
foreach (var region in Configuration.ConfigString("str_Regions").Split(','))
{
string Radio = "Radio" + (i++).ToString();
displayText = displayText + "<li><input type=\"radio\" id=" + Radio + " name=\"region\" value=" + region +
" runat=\"server\">" + region + "</input></li>";
}
%>
<%=displayText%>
</ul>
It appears that attempting to access the state of a radio button using "if(Radio1.Checked)
" in the code-behind results in a null reference exception.
To address this issue, I aim to determine which radio button has been selected through the user control's code behind and execute specific actions by reading the selected button's value. What would be the recommended approach to achieve this functionality?