Take the 2-minute tour ×

I have a RadioButtonList which has AutoPostBack set to True and is being handled server-side:

<asp:radiobuttonlist ID="myRBL" OnSelectedIndexChanged="MyRBL_SelectedIndexChanged"
    RepeatDirection="Horizontal" AutoPostBack="True" runat="server">
    <asp:ListItem Selected="True">Choice 1</asp:ListItem>
    <asp:ListItem>Choice 2</asp:ListItem>

I want to "progressively enhance" this by adding a JavaScript function with the OnClick attribute. After adding OnClick="myFunction();", the serverside code is no longer called when JavaScript is disabled in the browser.

Has anyone got a way around this (do I have to implement the IPostBackEventHandler or am I missing something)?

UPDATE: 08-26-2010 4:31 p.m. Pacific

Apparently, the ASP.NET this control cannot submit with JavaScript disabled. Does anyone have a detailed solution to this?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

AutoPostBack uses JavaScript to post back after clicking a radio button. By setting the onclick attribute, this behaviour is overwritten, so you must add an additional event handler to the click event.

As far as I know, there's no simple way to do this in plain JavaScript, so I would recommend using jQuery:

share|improve this answer
Unfortunately, I cannot use JQuery here... –  IrishChieftain Aug 26 '10 at 22:30
I'm sure, there are other ways to add multiple event handlers to the click event. Searching Google for javascript add multiple event handlers presents a bunch of articles about different ways to do this. –  davehauser Aug 26 '10 at 22:45
Yes but I'm wary of the browser differences and am a total JS newbie. Thanks for the link, +1 :-) –  IrishChieftain Aug 26 '10 at 22:53
I'm marking this as the answer because it directly addresses the core problem I'm facing. –  IrishChieftain Aug 31 '10 at 13:57

The only way to check if the user has javascript enabled is from the client side.

Your best bet then is to add the function on the client side, rather than in the server code. jQuery handles this quite well, with something like:

$(function() {

If you're not using jquery you can do a document.getElementById() and whatnot to assign the click handlers.

This way if the client doesn't have javascript, the radiobuttons are completely untouched.

share|improve this answer
If the user had JavaScript disabled, then this won't work? –  IrishChieftain Aug 26 '10 at 22:24
@IrishChieftain - perhaps I misunderstood. Isn't that the point? That you don't want the onClick enhancement if javascript is disabled? –  womp Aug 26 '10 at 22:26
I see what you mean... wire it up in the body onload? –  IrishChieftain Aug 26 '10 at 22:33
@IrishChieftain - Yeah, or even better just add it in an external script. If the user doesn't have javascript enabled the script won't even be loaded. –  womp Aug 26 '10 at 22:49
Marked as answer plus up vote, thanks :-) –  IrishChieftain Aug 26 '10 at 22:52

Your Answer


