Showing posts with label Java Script in ASP.Net RadioButtonList. Show all posts
Showing posts with label Java Script in ASP.Net RadioButtonList. Show all posts

Sunday, February 3, 2008

Java Script in ASP.Net RadioButtonList


The below sample code shows how to fire an event for a RadioButtonList control of Asp.Net.

The sample contains the java script function and additionally you need to add the following code in the Page_load event of aspx.cs -
RadioButtonList1.Attributes.Add("onclick","RadioCheck(this);");

function RadioCheck(obj)
{
var srcEl = event.srcElement;
// If the Radio's label is cliked the OnClick is fired twice. To avoid this
if(srcEl.tagName == 'LABEL')
return;

var srcObj = document.getElementById(obj.id+"_"+srcEl.parentElement.parentElement.rowIndex);
if(srcObj)
alert("Selected Radio's Value - "+srcObj.value);
}