Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery 'Change' event handler for asp.net radiobuttonlist not triggering event

I wired the Change event handler for an ASP.NET radiobuttonlist like this in the ready() handler in jQuery like this:

$("#<%=rblYesNo.ClientID%>").change(MyFunction);

When I select one of the radio buttons, MyFunction doesn't get called. Why?

like image 459
Tony_Henrich Avatar asked Aug 11 '09 15:08

Tony_Henrich


3 Answers

Remember, a radio button list doesn't have a single identifier. The radio buttons are linked together by their NAME. If I recall, rblYesNo.ClientID will probably be just a div that wraps the radio buttons. Try:

$("#<%=rblYesNo.ClientID%> input").change(function(){

});
like image 133
aquinas Avatar answered Nov 20 '22 00:11

aquinas


IE has a problem with the 'change' event on radio buttons, try using click instead:

$("#<%=rblYesNo.ClientID%>").click(MyFunction);
like image 24
karim79 Avatar answered Nov 20 '22 00:11

karim79


$("#<%=rblYesNo.ClientID%> input").change(function(){ });

and

$("#<%=rblYesNo.ClientID%>").click(MyFunction);

it may works in simple page. what if there is AjaxControlToolkit TabPanel in page? it will not works. Because radio button list will be on other tab so it will find by the jquery and event cannot registered.

like image 3
DineshHona Avatar answered Nov 20 '22 00:11

DineshHona