How to enable disable panel using jquery.

Posted on 2012-08-10
Last Modified: 2012-08-29
I have the following code,
<asp:TextBox id="txtreceivingreport" Text="" runat="server">
I want when the user enters the anything in textbox, the panel should be enabled
<asp:Panel id="p1" runat="server" Enabled="false">
<asp:RadioButton id="rbmale" runat="server" Text="Male">
<asp:RadioButton id="rbfemale" runat="server" Text="FeMale">
Question by:searchsanjaysharma
    LVL 2

    Expert Comment


    You can do using the OnTextChanged event on Text box. And you can handle Page partial rendering using

     <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
    LVL 35

    Accepted Solution

    I agree it may be better on server side but if you want to do it client side with jQuery use something like this:
                $('#txtreceivingreport').keyup(function (e) {
                    if ($(this).val() == "") {
                        $('#p1').addClass('aspNetDisabled').find('input[type=radio][id^=rb]').each(function () { $(this).attr('disabled', true); });
                    } else {
                        $('#p1').removeClass('aspNetDisabled').find('input[type=radio][id^=rb]').each(function () { $(this).attr('disabled', false); });

    Open in new window

    By the way I'm still learning jQuery myself so there may be a quicker way, also I'm not sure if you need to mess with the class on the div but it seemed a logical addition.
    LVL 81

    Expert Comment

    Don't use :
    <asp:Panel id="p1" runat="server" Enabled="false">
    <asp:Panel id="p1" runat="server" style="display:none">

    Now you can use :
    $("#<%= txtreceivingreport.ClientID %>").keyup(function() {
         if( $(this).val().length>0 ) $("#<%= p1.ClientID %>").show();

    Open in new window


    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
    How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now