Tuesday, August 14, 2012


A Simple way to clear all text-box fields using a single JavaScript function to avoid post backs in Asp.net


  • Just add the below code in Head tag within your .aspx page



<script type="text/javascript">
function btnclear_onclick()
{
     for(i=0; i < document.forms[0].length; i++)
     {
          if (document.forms[0][i].type == "text" || document.forms[0][i].type == "textarea")
          {
             document.forms[0][i].value="";             
          }
     }
     return false;
}
</script>

  • Now Add the following code snippet in Button's OnClientClick property

      return btnclear_onclick();

0 comments:

Post a Comment