You must Sign In to post a response.
  • Category: JavaScript

    How to disable panel in javascript that contain 2 link button

    How to disable panel in javascript that contain 2 link button(All and None).How to do that I tried like this but does not worked.Does anybody have any idea about this? document.getElementById("<%=mypanel.ClientID%>").disabled=true;All are asp.net server contol not html
  • #765823
    An asp:Panel just produces a div element. This isn't a form control, it's just there for structure.

    To disable every input control inside of it, if you are using jQuery,
    $("#<%=mypanel.ClientID%> input").attr("disabled", true);
    OR
    in Javascript
    var controls = document.getElementById("<%=mypanel.ClientID%>").getElementsByTagName("input");
    for (var i = 0; i < controls.length; i++)
    controls[i].disabled = true;

  • #765825
    Hi

    Try this code working


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    <script>
    function DisabledPanel() {
    $("#<%=pnl.ClientID%> input").attr("disabled", true);
    return false;
    }
    </script>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:Panel ID="pnl" runat="server">
    <asp:TextBox ID="TxtName" runat="server"></asp:TextBox>
    </asp:Panel>
    <asp:Button ID="Btn" runat="server" OnClientClick="return DisabledPanel();" />
    </form>
    </body>
    </html>


    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #765826
    Hi

    Try one more code


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    <script>
    function DisabledPanel() {
    var controls = document.getElementById("<%=pnl.ClientID%>").getElementsByTagName("input");
    for (var i = 0; i < controls.length; i++)
    controls[i].disabled = true;
    return false;
    }
    </script>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:Panel ID="pnl" runat="server">
    <asp:TextBox ID="TxtName" runat="server"></asp:TextBox>
    </asp:Panel>
    <asp:Button ID="Btn" runat="server" OnClientClick="return DisabledPanel();" />
    </form>
    </body>
    </html>

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #765830
    you can use the disabled attribute for your panel
    Following is the jquery sample code for do this.

    $("#<%=mypanel.ClientID%> input").attr("disabled", true);

    By Nathan
    Direction is important than speed

  • #766252
    Hi Pinky,

    You can try with this code also :-

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    <script type = "text/javascript" language="javascript">
    function hidePanel()
    {
    document.getElementById('<%= pnlContent.ClientID %>').style.display = "none";
    return false;
    }
    function showPanel()
    {
    document.getElementById('<%= pnlContent.ClientID %>').style.display = "";
    }
    </script>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:Panel ID="pnlContent" runat="server" Height="50px" Width="125px">
    Hello India</asp:Panel>
    <br />
    <br />
    <br />
    <asp:LinkButton ID="lnkAll" OnClientClick="javascript:return showPanel();" runat="server" >All</asp:LinkButton> 
    <asp:LinkButton ID="lnkNone" OnClientClick="javascript:return hidePanel();" runat="server" >None</asp:LinkButton></div>
    </form>
    </body>
    </html>



    Hope it will solve your problem.

    Thanks

  • #766256
    when we run our application the 'asp:Panel' itself shows as DIV so in javascript code you need to disable DIV only.
    use below javascript function to disable it

    <script langiage="javascript">
    var controls = document.getElementById("<%=mypanel.ClientID%>").getElementsByTagName("input");
    for (var i = 0; i < controls.length; i++)
    controls[i].disabled = true;
    </script>

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #766709
    HI,

    $(function(){
    $('#btndisable').click(function(){
    $('#Panel1 input').each(function(){
    $(this).attr('disabled', true);
    });

    });
    });


Sign In to post your comments