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 the following single line of code for the button’s OnClientClick event (you don’t require any code in a .cs page).

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

Check the code: 

  1. <form id="”form1″" runat=”server”>  
  2.     <div>  
  3.         <table class=”style1″>  
  4.             <tr>  
  5.                 <td class=”style3″>  
  6.                     Name </td>  
  7.                 <td class=”style4″>  
  8.                     <asp:TextBox ID="”txtNM”" runat=”server” Text=”">  
  9.                     </asp:TextBox>  
  10.                 </td>  
  11.             </tr>  
  12.             <tr>  
  13.                 <td class=”style3″>  
  14.                     Password</td>  
  15.                 <td class=”style4″>  
  16.                     <asp:TextBox ID="”txtPS”" runat=”server” TextMode=”Password”>  
  17.                     </asp:TextBox>  
  18.                 </td>  
  19.             </tr>  
  20.             <tr>  
  21.                 <td class=”style3″>  
  22.                     Gender</td>  
  23.                 <td class=”style4″>  
  24.                     <asp:RadioButtonList ID="”RadioButtonList1″" runat=”server” RepeatDirection=”Horizontal”>  
  25.                         <asp:ListItem>Male</asp:ListItem>  
  26.                         <asp:ListItem>Female</asp:ListItem>  
  27.                     </asp:RadioButtonList>  
  28.                 </td>  
  29.             </tr>  
  30.             <tr>  
  31.                 <td class=”style3″>  
  32.                     Course</td>  
  33.                 <td class=”style4″>  
  34.                     <asp:DropDownList ID="”DropDownList1″" runat=”server”>  
  35.                         <asp:ListItem>-Select-</asp:ListItem>  
  36.                         <asp:ListItem>.NET</asp:ListItem>  
  37.                         <asp:ListItem>JAVA</asp:ListItem>  
  38.                         <asp:ListItem>PHP</asp:ListItem>  
  39.                     </asp:DropDownList>  
  40.                 </td>  
  41.             </tr>  
  42.             <tr>  
  43.                 <td class=”style3″>  
  44.                      </td>  
  45.                 <td class=”style4″>  
  46.                      </td>  
  47.             </tr>  
  48.             <tr>  
  49.                 <td class=”style2″ colspan=”2″>  
  50.                     <asp:CheckBox id="”chk”" runat=”server”/> Agree with T&C ?</td>  
  51.             </tr>  
  52.         </table>  
  53.         <br />  
  54.         <asp:Button id="”btn”" runat=”server” Text=”Clear” OnClientClick=”this.form.reset();return  
  55.             false;”CausesValidation=”false”/>  
  56.     </div>  
  57. </form>  


Similar Articles