Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET radiobuttonlist onclientclick

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!!!)

like image 681
jaffa Avatar asked Apr 27 '10 18:04

jaffa


1 Answers

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.

like image 81
Daniel Ballinger Avatar answered Sep 30 '22 00:09

Daniel Ballinger