By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 2,139 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

Radiobutton always has Checked = true, even when not selected

P: n/a
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

--
Alan Silver
(anything added below this line is nothing to do with me)
Jul 19 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

Alan Silver wrote:
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

--
Alan Silver
(anything added below this line is nothing to do with me)
Jul 20 '06 #2

P: n/a
In article <11**********************@p79g2000cwp.googlegroups .com>,
ne**********@gmail.com writes
>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

Alan Silver wrote:
>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

--
Alan Silver
(anything added below this line is nothing to do with me)
--
Alan Silver
(anything added below this line is nothing to do with me)
Jul 20 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.