ASP.Net/C# - Radiobutton, anyway to deselect a radio button in a group to have none selected?

Hi all.  I am trying to not change these controls to checkboxes but I have a radiobutton with a groupname.  Is there anyway I can allow the user one they select one to unselect it so there is none selected of that group?
sbornstein2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bmcvicarCommented:
Sbornstein,

Once a radio button is selected/enabled in group you can not deselect it.  The
What about creating an extra radio button with (No Selection) or (None) next to it for the user to select?
0
sbornstein2Author Commented:
ya I might do that none.  I will try that in a bit.
0
sbornstein2Author Commented:
what about a checkboxlist?  See what I do is in code I create the radiobuttons dynamically and then set the groupname to it all in code.  Checkboxes dont have a groupname I beleive so is there a way to have a checkboxlist item in place of the radio button?
0
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

bmcvicarCommented:
The checkbox and checkboxlist don't have the groupname property.  
Are you only generating one radiobutton per group?  If you are generating more then one item per group then with the checkboxlist the user will be able to check more then one item.
0
VelioCommented:
hi

you can do this with radio buttons, all you need is a little client-side scripting.

for each Radio Button in the group, add the following onclick attribute, for example:
RadioButton1.Attributes.Add("onclick", "if (checkedRadio == this) { this.checked = false; } else { checkedRadio = this; }");
RadioButton2.Attributes.Add("onclick", "if (checkedRadio == this) { this.checked = false; } else { checkedRadio = this; }");

then, in your ASPX page, add the following script inside the <head> tag:
    <script language="javascript" type="text/javascript">
        var checkedRadio;
    </script>

this will cause the currently selected radio button to get deselected whenever it is clicked again. hope it helps.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bmcvicarCommented:
Velio,

Just a heads up, when using the javascript you provided you run into some interesting issues-  
Try to click the first radiobutton 3 times or select 2 then click on the first one again ( you will have to double click).

I think your code is on the right path though, my only concern would be user experience.
0
VelioCommented:
ah yes, well spotted bmcvicar, resetting the checkedRadio variable once a radio button is "deselected", so that it can be selected again, should fix this.

the javascript to execute in the onclick event then becomes this:

if (checkedRadio == this) { this.checked = false; checkedRadio = null; } else { checkedRadio = this; }
0
sbornstein2Author Commented:
Thanks guys sorry it too me so long to grade this.  I went with another option but I think I am going to change to this.    Thanks alot.  I will post if I have any issues.
0
xselluserCommented:
I added to the js which fixes the issue with clicking the radio button multiple times.

if (checkedRadio == this) { this.checked = false; checkedRadio = null;} else { checkedRadio = this;}

By setting checkedRadio to null, you are able to select the radiobutton, then deselect, and then select again.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.