Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I want call a code behind function in radio button on click event

XML
<asp:RadioButtonList ID="grpLocation" runat="server" RepeatDirection="Horizontal"
OnDataBound="grpLocation_onDataBound">
</asp:RadioButtonList>



C#
RadioButtonList rbl = (RadioButtonList)sender;
       foreach (ListItem li in rbl.Items)
       {
           li.Attributes.Add("onclick", "javascript:ShowExt('" + li.Value + "')");
       }



XML
<script language=javascript type="text/javascript">
   function ShowExt(object)
   {
   alert("Value Clicked :" + object);
   }
   </script>


am using this code but i need to call a function inside the script block please give ur suggestion and sample code thank you
Posted
Updated 29-May-12 2:40am
v3

1 solution

Here's a simple example on button click event of Radio Button :

XML
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" />
<script src="http://code.jquery.com/jquery-1.5.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script>
<script language="javascript">
function choixPersonne(chaine)
{
var a = document.getElementById("rien");
var b= document.getElementById("option");

if (chaine == 'cacher1'){

a.style.display = "none";
b.style.display = "block";
}
else if (chaine == 'cacher2'){

a.style.display = "block";
b.style.display = "none";
}

}
</script>

</head>
<body>

<div data-role="page" data-theme="b">
<div data-role="header">
<h1>Quel vin boire, choisir, servir ?</h1>
</div> <!-- /header-->

<div data-role="content">
<div class="ui-body ui-body-a">
<form action="" name="recherche" id="recherche" method="post">
<fieldset data-role="controlgroup">
<input type="radio" name="personne" id="ouiCli" value="oui" onchange="choixPersonne('cacher1')" checked="checked" />
<label for="ouiCli" >plats/mets</label>
<input type="radio" name="personne" id="nonCli" value="non" onchange="choixPersonne('cacher2')" />
<label for="nonCli">vins</label>
<label for="query">Entrez votre plat ou votre vin</label>
<input type="text" name="query" size="37" value="" />

<!--Les champs à masquer:-->
<div id="rien" style="display:none"><fieldset class="Style7">
</fieldset></div>
<div id="option" style="display:none"><fieldset class="Style7">
<label style="display:inline"><br>Nos accords mets et vins fonctionnent uniquement avec les appellations (Exemple : Sauternes, Chinon etc..)</label>
</fieldset>
</div>
</fieldset>
<input type="submit" name="button" value="rechercher" />
</form>
</div>
</div><!-- /content-->
</div><!-- /page-->

</body>
</html>


You can also try jQuery :

C#
$("input[type='radio']").change(function () {
var selection=$(this).val();
alert("Radio button selection changed. Selected: "+selection);
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900