Click here to Skip to main content
12,633,990 members (24,569 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
I want call a code behind function in radio button on click event

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



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



<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 29-May-12 3:38am
Updated 29-May-12 3:40am
v3

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

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

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 29 May 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100