How to fire the client side onclick() event of asp radio button?

In this tutorial you will learn how to fire the client side onclick() event of asp radio button. Using same technique you can fire the onclick() event of asp textbox, asp button, etc too. It is not a big deal. Let's have a look over how to do so.

How to fire the client side onclick() event of asp radio button?


The method to do this is very simple, you just have to write the
onclick="yourjavascriptfunction();"
and that’s it.

One thing remember that the intelliSense of visual studio will not show you the onClick() event in the list of available events for asp radio button when you will press the spacebar but you have to write this yourself in order to execute your javascript code using client side onclick() event of asp radio button because when your aspx page is rendered then asp radio button will become input radio button.

Now let's have a look over the complete example of the topic that we are discussing.

Home.aspx

<script language="javascript" type="text/javascript">
function ShowAlert()
{

alert("client side onClick event of asp radio button has been fired");

}
</script>
<table cellpadding="0" cellspacing="2" border="0" width="100%">
<tr>
<td width="28%">First Name:</td><td><asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Last Name:</td><td><asp:TextBox ID="txtLastName" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Do you want to join us?</td><td><asp:RadioButton ID="rdoYes" runat="server" GroupName="Group1"
Text="Yes" onclick="ShowAlert();"/> <asp:RadioButton ID="rdoNo" runat="server" GroupName="Group1" Text="No"  onclick="ShowAlert();"/></td>
</tr>
</table>
So that's it. I hope you will find this tutorial very informative.

0 comments: