Handling ASP.Net Control Using Scriptlets And jQuery


Handling ASP.Net Control Using Scriptlets And jQuery


In this post I’ll show how we can handle ASP.Net Controls on client side using Scriptlets and jQuery.

For this post I’ll be using RadioButtonList Control as an example to demonstrate the use of Scriptlets and jQuery.

Button before proceeding further, lets have a brief loot at what Scriptlets actually is,

In JavaServer Pages (JSP) technology, a scriptlet is a piece of Java-code embedded in the HTML-like JSP code. The scriptlet is everything inside the <% %> tags. Between these the user can add any valid Scriptlet i.e. any valid Java Code.

Now coming back to our post, here I’ll be using Scriptlets in .Net using jQuery.



<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="jquery.min.js"></script>
        function getRadioButtonListValue() {
            var rblValue = $("#<%=rblItem.ClientID%>").find(":checked").val();
            if (rblValue == "ITEM_A")
                $("#divItemA").css({ "visibility": "visible", "display": "normal" });
                $("#divItemB").css({ "visibility": "hidden", "display": "none" });
            else if (rblValue == "ITEM_B")
                $("#divItemA").css({ "visibility": "hidden", "display": "none" });
                $("#divItemB").css({ "visibility": "visible", "display": "normal" });

<form id="form1" runat="server">

            <asp:RadioButtonList ID="rblItem" runat="server" AutoPostBack="false"                 RepeatDirection="Horizontal" name="option" onclick="getRadioButtonListValue();">
                <asp:ListItem Value="ITEM_A">ITEM_A</asp:ListItem>
                <asp:ListItem Value="ITEM_B">ITEM_B</asp:ListItem>

<div id="divItemA" style="visibility: hidden; display: none">

<h2>You have selected ITEM A</h2>


<div id="divItemB" style="visibility: hidden; display: none">           

<h2>You have selected ITEM B</h2>





Here, below line of code is the scriptlet code,


var rblValue = $("#<strong><%=rblItem.ClientID%></strong>").find(":checked").val();



itema itemb






JavaScript, ASP.Net & PHP Web Developer. Connect with me on Facebook and Twitter.

Share This Post

Related Articles

Powered by Paras Babbar · Designed by Paras Babbar