• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 901
  • Last Modified:

How to enable disable panel using jquery.

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">
1 Solution

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" />
Robert SchuttSoftware EngineerCommented:
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.
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

searchsanjaysharmaAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now