Tuesday, 13 January 2015

Pin It

Widgets

Enable-Disable a Panel using Javascript in ASP.NET

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="DemoGrid.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <script type="text/javascript">
            function Enable() {
                var controls = document.getElementById("<%=mypanel.ClientID%>").getElementsByTagName("input");

                for (var i = 0; i < controls.length; i++) {
                    controls[i].disabled = false;
                }
            }

            function Disable() {
                var controls = document.getElementById("<%=mypanel.ClientID%>").getElementsByTagName("input");

                for (var i = 0; i < controls.length; i++) {
                        controls[i].disabled = true;
                }
            }
        </script>
            <asp:Panel ID="mypanel" runat="server">
                <asp:TextBox runat="server" />
                <asp:TextBox runat="server" />
                <asp:CheckBox Text="text" runat="server" />
                <asp:Button runat="server" Text="Dummy" />
            </asp:Panel>
            <input type="button" name="name" value=" Disable" onclick="Disable();" />
            <input type="button" name="name" value=" Enable" onclick="Enable();" />
    </form>
</body>
</html>

No comments: