Hi All,

I have a aspx page with few controls. When i am using reset button to reset the form its working fine before saving, its notworking after save the form. Can you help me on this.

i used OnClientClick="document.location.href=document.location.href;" for the Reset Button.

Thanks in advance.

So, when you hit the reset button, you are simply reloading the page and of course since the page had no values when you first loaded it, reloading the page results in the same clean form.

However, when you submit the form, because of viewstate, the values are still populated in your form. If you disable viewstate for that page, the values will be cleared from your form on each postback. Your reset button, while it seems is working, its just simply performing an autopostback.

In your code behind, you can clear the input elements manually. But I would suggest doing this client side...no need to post back to the web server to simply clear a few textboxes...

Using javascript, or actually even easier with jQuery.

Something like this..

<script>
  $('#resetForm').click(function(){
    $('input').val("");
  });
</script>

Instead of using an ASPX control, just add an HTML button to your page. something like this..

<button id="resetForm">Reset</button>

Then just make sure that you are including jQuery in your page...in the head section..

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.