Friday, April 6, 2007

Client Side Event Handlers Appear to Short Circuit RadioButton Server Side Handled

ASP.Net 2.0 RadioButton

I had a handler for the body tag's OnLoad event and that did not seem to conflict with the Page_Load server event. In that event I did something like this:

document.getElementById("rbDocView").onclick=function(){ RadioClick();}
document.getElementById("rbItemView").onclick=function(){ RadioClick();}

Once I added this the server side CheckChanged event stopped firing.

Changing Value of RadioButton Does Not Change Form

ASP.Net 2.0 Server Side RadioButton
I had two RadioButtons in the same group on a form. I created a server side handler for the CheckChanged event. If a certain criteria was true then I needed to show an error and set the checked property back to its previous value. The problem I ran into was that it wasn't updating the form.

As I looked at the source of the page I found that both radiobuttons had their checked attribute set to "checked". It appears that it displays as checked whichever is the last radiobuton with its attribute set. The remedy was to manually set both radiobuttons' checked property on the server and not assume that setting the checked property to true of one that is in the same group that the other would automatically get set to false.