asp:RadioButton runat="server" - want to react to click event on client side



I've wasted the whole day trying things and researching, but nothing is
working. I would *greatly* appreciate if someone can give me the
solution to this problem.

I'm using the .NET Framework 2.0 in C# with a Master page and
additional .aspx pages with .cs code-behind pages in Windows XP.

In an .aspx page I have declared a control as follows:
<asp:RadioButton runat="server" GroupName="rbtnS0"
ID="rbtnS0start" />

I want to do some event-side work whenever this RadioButton is clicked.
I've tried everything I've found, e.g., putting
rbtnS0start.Attributes.Add("OnClick", "rbtnS0start_Click();");
in the .cs file's Page_Load event, and then specifying
<script type="javascript">
function rbtnS0start_Click()
in the asp:Content section of the .aspx file. I get an "error on page"
from IE6 whenever I click that button. I've tried dozens of
combinations of things. (Unfortunately, there is no OnClick attribute
for an asp:RadioButton.)

Can someone *please* give me the code (and where it goes) so that I can
do client-side work when the user clicks an asp:RadioButton control?

Thank you *so much* to anyone who helps!

bruce barker

you need to legal javascript syntax to define the function.

<script type="javascript">
function rbtnS0start_Click() {

Mark Rae

you need to legal javascript syntax to define the function.

<script type="javascript">

Or even

<script type="text/javascript">

if you want to be XHTML-compliant...


Oh what a difference a couple of curly braces make! Imagine 9 hours
wasted because I didn't have the curly braces :-(. Thank you both very


Ok, now I want to work with my client controls (instead of just popping
up an alert). For instance when they click rbtnS0start I want the
javascript on the client to set rbtnS1start (another asp:RadioButton)
to be 'checked=true'. I've tried things like: rbtnS1start.Checked =
true; but apparently that's not right because it doesn't check the
button or execute the rest of my javascript.

Obviously I'm quite new to client-side scripting, so any help/pointers
you can provide would be most appreciated. (Btw, I'm on the clock, so
the sooner someone will help me the better.)

Thank you!!


Well I finally figured out a way to do this. I couldn't get the
document.getElementById thing to work, and I'm sure there must be a
more concise way to do this (for example, passing an array) but I don't
know Javascript well enough. At this point, I don't care. I got it to
work, so I'm supplying the complete solution for the other poor souls
out there trying to do the same thing. As a reminder, what this does
is, when the user clicks the asp:RadioButton whose ASP ID is
rbtnS0start, I want the client to run Javascript in the .aspx page so
that the asp:RadioButtons named rbtnS1start thru rbtnS6start
automatically get checked.

In the code-behind page I have this code:
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
rbtnS0start.Attributes.Add("OnClick", "rbtnS0start_Click("
rbtnS1start.ClientID + "," +
rbtnS2start.ClientID + "," +
rbtnS3start.ClientID + "," +
rbtnS4start.ClientID + "," +
rbtnS5start.ClientID + "," +
rbtnS6start.ClientID +

In the .aspx page, I included the following code just before the
</asp:Content> tag (which is the last tag on the page)...
<script type="text/javascript">
function rbtnS0start_Click(b1,b2,b3,b4,b5,b6)
b1.checked = true;
b2.checked = true;
b3.checked = true;
b4.checked = true;
b5.checked = true;
b6.checked = true;

Could this have possibly been made any harder to do!!??

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question