c# - how to Clear textBox after CompareValidator caught wrong datatype? -


and beginner in using asp.net , c# in visual studio 2008

i have textbox id = limitamount, supposed accepts input of type double, therefore made comparevalidator (comparevalidatoramount) control this, want textbox cleared after invalid input type.

thank !

use custom validator:

  <asp:customvalidator id="customvalidator1"        controltovalidate="limitamount"        onservervalidate="servervalidation"        errormessage="this field requires number"        forecolor="red"        runat="server"/>          

in code behind:

  void servervalidation(object source, servervalidateeventargs args)   {      double tmp;      if(double.tryparse(args.value, out tmp))      {         args.isvalid = true;      }      else      {         args.isvalid = false;         limitamount.text = string.empty;      }   } 

if prefer, can validate in javascript clientvalidationfunction


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -