Let’s Create Reset/Clear Button in ASP.NET WebForm Using Javascript…

 

See Demo

Download Code

Hello,

Here is the code of Clear Button

You need to add following single line of code at button’s OnClientClick event(you don’t require any code at .cs page)

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

 

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=”style3″>
&nbsp;</td>
<td class=”style4″>
&nbsp;</td>
</tr>

<tr>
<td class=”style3″>
Address</td>
<td class=”style4″>
<asp:TextBox ID=”txtADD” runat=”server” TextMode=”MultiLine” Height=”70px”></asp:TextBox></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>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s