My site has language change control so when a language is clicked I reload the same page but with different language text, and if the user has already field in the form I have to reload the data.
I have managed to reload data into checkboxes, textbox but not with radio botton
Please see my code
I have a datalist and a radio button inside.
<asp:DataList runat="server" ID="dlRole">
<ItemTemplate>
<input type="radio" id="rblRole" name="rblRole" value='<%# Eval("RoleCode") %>' />
<asp:Label ID="lbRole" runat="server" Text='<%# Eval("Description")%>'></asp:Label>
</ItemTemplate>
</asp:DataList>
I load the datalist, radio buttons
dlRole.DataSource = ...
dlRole.DataBind();
I save the radio button value into user session object
user.Role = Request["rblRole"];
but when I reload the saved object into radio button, it cannot find the radio button object control.... radio button is always NULL. and I am not sure why
foreach (DataListItem item in dlRole.Items)
{
HtmlInputRadioButton radio = (item.FindControl("rblRole") as HtmlInputRadioButton);
if (radio != null) <--- always nulll
{
if (radio.Value == user.Role.ToString())
{
radio.Checked = true;
}
else
radio.Checked = false;
}
}
please let me know how to fix that thank you
You need to add
runat="server"
on you radio button otherwise it will not be accessible from the Code Behind.