views:

78

answers:

2

I've got a project I'm working on where I need to put a RadioButton inside a ListView, and have them all have the same GroupName. (can't use RadioButtonList, long story).

Anyway, this seems to be a well known bug in .NET, so I've implemented the solution found here:
http://stackoverflow.com/questions/377393/asp-net-radiobutton-messing-with-the-name-groupname

This works perfectly, but with one small bug which undoubtedly will come back to bite me. If I click one radio button, and then click another while the javascript function is still running and has not completed; I can get 2 radiobuttons in the same group selected.

Any ideas? If you need clarification; leave me a comment and I'll update my post.

EDIT: I believe I fixed my own issue here. See my posted answer below.

+1  A: 

Would something like this work?

if (!rbClicked)
    rbClicked=True;
    runJavascript();
    rbClicked=False;

I admit I didn't do alot of research, but this is how I've usually solved this type of problem.

Ian Jacobs
A: 

Turns out I was misguided here.

Later on in the page lifecycle; I was adding an additional onclick event that was overwriting the previous value.

In the following example:

var radiobutton = new System.Web.UI.WebControls.RadioButton();
radiobutton.Attributes.Add("onclick", "test1");
radiobutton.Attributes.Add("onclick", "test2");

the onlcick attribute is set to "test2"; test1 is lost.

I ended up fixing it by appending to the existing attribute; see below:

radiobutton.Attributes["onclick"] = string.Format("{0};{1}", radiobutton.Attributes["onclick"], "My Second Script");

This works without issue.

Jim B