is there an easy way to reset ALL text fields in an asp.net form - like the reset button for html controls?
Asked
Active
Viewed 2.6k times
11
-
duplicate http://stackoverflow.com/questions/3794136/clear-all-fields-in-asp-net-form – crh225 Oct 23 '13 at 15:08
7 Answers
7
This works for me:
<asp:Button ID="btnReset" runat="server" Text="Reset"
OnClientClick="this.form.reset();return false;" />

ocean4dream
- 5,082
- 1
- 15
- 17
-
-
in order to prevent the default action of clicking the button and only run this portion of code that he wrote – hamada147 Aug 28 '17 at 09:17
-
7
Depends on your definition of reset. A trivial way to do something like this could be a button with codebehind:
Response.Redirect(Request.Url.PathAndQuery, true);
Or a variation thereof.

aanund
- 1,483
- 11
- 18
5
<input type="reset" value="Clear" />

Bat_Programmer
- 6,717
- 10
- 56
- 67
-
2I'm surprised this answer was not given already. It would be more useful with a bit more detail; Explain that an ASP.NET form is really just an HTML form, and so putting that control inside the ` – Andrew Barber Jan 15 '13 at 22:13
-
3
Using javascript you can do:
document.forms[0].reset();
or
theForm.reset(); // at least with ASP.NET 2.0
As in
<input type='button' id='resetButton' value='Reset' onclick='theForm.reset();return false;' //>

tvanfosson
- 524,688
- 99
- 697
- 795
1
Some solutions are listed here:
I was looking for the same solution in ASP.Net to clear my form on the click and I landed on this post. I looked at all the comments and replies. I decided to use the plain old input tag and created a HTML reset button .It worked like a charm, no postbacks, not javascripts. If there is any catch, I couldn't find it...

DaveK
- 4,509
- 3
- 33
- 33
0
This should work:
function resetForm()
{
var inputs = document.getElementsByTagName('input');
for(var i=0;i<inputs.length;i++)
{
if(input[i].type == 'text')
input[i].value = "";
}
}

Stefan
- 1,719
- 2
- 15
- 27
-1
The easiest way to clear all controls in your form on a submit is:
form1.Controls.Clear()

Dubs
- 420
- 5
- 12
-
1form.controls.clear() will remove all controls from form, reset form is to clear control's values – Pedro Muniz May 16 '13 at 17:03