Radiobutton always has Checked = true, even when not selected

A

Alan Silver

Hello,

I have a pair of radiobuttons on a form, used to select the type of
search someone is to do...

<asp:RadioButton ID="rdbLastNDays" Text="Show tips for the last"
GroupName="rbgSearch" runat="server" />

and

<asp:RadioButton ID="rdbContainingWords" Text="Show tips containing the
word(s)" GroupName="rbgSearch" runat="server" />

Then in my code, I check like this...

if (rdbLastNDays.Checked) {
// do stuff based on the first radiobutton
} else {
// do stuff based on the second
}

The problem is that the condition in the if statement is *always* true.
In other words, rdbLastNDays is always showing as checked, even when it
isn't. The "else" part never, ever gets executed.

Anyone any idea why this is happening? TIA
 
N

neilmcguigan

works fine for me on asp.net 2.0

<form id="form1" runat="server">

<asp:RadioButton ID="one" GroupName="group" runat="server"
Text="one" />
<asp:RadioButton ID="two" GroupName="group" runat="server"
Text="two" />

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />
</form>

protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(one.Checked); Response.Write(two.Checked);
}

output is FalseFalse
 
A

Alan Silver

works fine for me on asp.net 2.0

Yup, normally does for me too, but in this instance, it fails!!

I have discovered that it's only one of the two radiobuttons that does
this, the other works as expected. This gives me a workaround, but I'm
puzzled why one should always have the Checked property true, even when
it's not selected.

Thanks anyway. Ta ra
<form id="form1" runat="server">

<asp:RadioButton ID="one" GroupName="group" runat="server"
Text="one" />
<asp:RadioButton ID="two" GroupName="group" runat="server"
Text="two" />

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />
</form>

protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(one.Checked); Response.Write(two.Checked);
}

output is FalseFalse
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top