Click here to Skip to main content
13,351,225 members (32,951 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I want call a code behind function in radio button on click event

<asp:RadioButtonList ID="grpLocation" runat="server" RepeatDirection="Horizontal"


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

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

1 solution

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

Solution 1

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

<!DOCTYPE html>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="" />
<script src=""></script>
<script src=""></script>
<script language="javascript">
function choixPersonne(chaine)
var a = document.getElementById("rien");
var b= document.getElementById("option");

if (chaine == 'cacher1'){ = "none"; = "block";
else if (chaine == 'cacher2'){ = "block"; = "none";



<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">
<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>
<input type="submit" name="button" value="rechercher" />
</div><!-- /content-->
</div><!-- /page-->


You can also try jQuery :

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

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 |
Web01 | 2.8.180111.1 | Last Updated 29 May 2012
Copyright © CodeProject, 1999-2018
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