views:

175

answers:

3

I've noticed there is no OnClientClick() property for the radiobuttonlist in the ASP.NET control set. Is this a purposeful omissiong on Microsoft's part? Anyway, I've tried to add OnClick to the radio button list like so:

For Each li As ListItem In rblSearch.Items
    li.Attributes.Add("OnClick", "javascript:alert('jon');")
Next

But alas, it doesn't work. I've even checked the source in firebug, and there is no javascript shown in the radiobuttonlist. Does anyone know how to get this very simple thing working? I'm using ASP.NET control adpaters so don't know if that has anything to do with it.

(I wish asp.net/javascript would just work out the box!!!)

A: 

Because it's a list control, there isn't a OnClientClick event. Either use a postback (SelectedIndexChange) or write javascript to grab the click for each radio button.

Dan
+1  A: 

http://www.4guysfromrolla.com/articles/091405-1.aspx

Read section on "why attributes cannot be applied to listitems of a list control"

Raj Kaimal
A: 

I found I could just add a onclick attribute to the RadioButtonList and it would fire the javascript client side as expected.

<asp:RadioButtonList ID="RadioButtonList1" runat="server" onclick="alert('RadioButtonListSelectChange');">
    <asp:ListItem Text="One" Value="1"/>
    <asp:ListItem Text="Two" Value="2"/>
</asp:RadioButtonList>

You could then write a client script that could determine the currently selected list item.

Daniel Ballinger