Tuesday, 13 January 2015

Pin It

Widgets

Clear Multiple Textboxes in ASP.Net on Button Click


<%@ 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 Clear() {
                var txts = document.getElementsByClassName('txts');

                for (var i = 0; i < txts.length; i++)
                    txts[i].value = '';

                return false;
            }
        </script>

        <div>
            <asp:TextBox ID="txt1" runat="server" CssClass="txts"></asp:TextBox>
            <asp:TextBox ID="txt2" runat="server" CssClass="txts"></asp:TextBox>
            <asp:TextBox ID="txt3" runat="server" CssClass="txts"></asp:TextBox>
            <asp:TextBox ID="txt4" runat="server" CssClass="txts"></asp:TextBox>

            <input type="button" name="name" value=" Clear" onclick="Clear();" />
        </div>
    </form>
</body>
</html>


No comments: