Create Reset Button in ASP.NET Webform Using JavaScript

Create Reset Button in ASP.NET Webform Using JavaScript

Here is the code of Reset Button.

You need to add Following single line of code for the button’s OnClientClick event (you don’t require any code in a .cs page).

OnClientClick=”this.form.reset();return false;” CausesValidation=”false

 

See Demo (http://aspspider.info/sobhagya/clearbutton.aspx)

Check the code:

<form id="”form1″" runat=”server”>

        <div>
            <table class=”style1″>
                <tr>
                    <td class=”style3″>
                        Name </td>
                    <td class=”style4″>
                        <asp:TextBox ID="”txtNM”" runat=”server” Text=”">
                        </asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td class=”style3″>
                        Password</td>
                    <td class=”style4″>
                        <asp:TextBox ID="”txtPS”" runat=”server” TextMode=”Password”>
                        </asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td class=”style3″>
                        Gender</td>
                    <td class=”style4″>
                        <asp:RadioButtonList ID="”RadioButtonList1″" runat=”server” RepeatDirection=”Horizontal”>
                            <asp:ListItem>Male</asp:ListItem>
                            <asp:ListItem>Female</asp:ListItem>
                        </asp:RadioButtonList>
                    </td>
                </tr>
                <tr>
                    <td class=”style3″>
                        Course</td>
                    <td class=”style4″>
                        <asp:DropDownList ID="”DropDownList1″" runat=”server”>
                            <asp:ListItem>-Select-</asp:ListItem>
                            <asp:ListItem>.NET</asp:ListItem>
                            <asp:ListItem>JAVA</asp:ListItem>
                            <asp:ListItem>PHP</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td class=”style3″>
                        &nbsp;</td>
                    <td class=”style4″>
                        &nbsp;</td>
                </tr>
                <tr>
                    <td class=”style2″ colspan=”2″>
                        <asp:CheckBox id="”chk”" runat=”server”/> Agree with T&amp;C ?</td>
                </tr>
            </table>
            <br />
            <asp:Button id="”btn”" runat=”server” Text=”Clear” OnClientClick=”this.form.reset();return
                false;”CausesValidation=”false”/>
        </div>
    </form>
 

Up Next
    Ebook Download
    View all
    Learn
    View all