Reputation: 1389
I have 3 radiobutton control and a submit button in my aspx page which are inside a Content control.
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<asp:Panel ID="Panel1" runat="server">
<asp:RadioButton ID="rd0" runat="server" GroupName="g1" Checked="true" />
<asp:Image ID="img0" runat="server" ImageUrl="/image/img0.png" />
<asp:RadioButton ID="rd1" runat="server" GroupName="g1" />
<asp:Image ID="img1" runat="server" ImageUrl="/image/img1.png" />
<asp:RadioButton ID="rd2" runat="server" GroupName="g1" />
<asp:Image ID="img2" runat="server" ImageUrl="/image/img2.png" />
</asp:Panel>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
</asp:Content>
The user can select one of these radiobuttons and press submit button. Now in code behind i want to diagnose which radiobutton is selected,
RadioButton checkedButton;
if (rd0.Checked)
checkedButton = rd0;
else if (rd1.Checked)
checkedButton = rd1;
else
checkedButton = rd2;
but the checked property of all of the radiobuttons is false.
I have even set the checked property of the first radiobutton to true but it becomes to false after postback again.
Upvotes: 0
Views: 1443
Reputation: 81
Do you have PostBack control in your Page_Load code section?
Try to add following code to your Page_Load event.
if(IsPostBack) return;
Upvotes: 1