Reset button that works across postback to same page

By definition, a HTML Reset button does not work after a form is postback to the same page, because the posted back values then become the "default" values of the form.
Although you can use Javascript to reset all the fields in the form, I usually resort to a more simple way. Just create a button with an onClick handler to visit the same page. The difference this time is that it will be a GET instead of a POST, so all fields in the form will be cleared and reset to the original defaults.
Yes, it takes a round trip to the server, but the logic is simple and portable.
=== Sample Code ===

<input type="button" onclick="window.location=''" value="Reset" />

No comments: