Hi J
One way you could do it is to take advantage of the Validation structure in .NET. Validation occurs first on the client side, so that if the validation criteria are not met, it won't post back the page. Then when the page is posted back, it validates again for two reasons:
1. to ensure that someone isn't hacking
2. in the case that client side validation has been disabled (a user can get trapped by validation so there is a way to turn it off eg. onclick="Page_ValidatationActive=false;" so that the page can be posted back)
This isn't perfect if you want to validate immediately on change
With a CustomValidator you can create whatever validation you want in the form of your own functions, both on the client and server side. It is V good practice to make sure that both functions do the same thing though. If you setup a custom validator to control your textbox validation you can set the ClientValidationFunction property and give it the name of a Javascript function in the HTML. You must setup your JScript function by passing the variables source and arguments (see below). Set the arguments.IsValid variable based on the result of your validation
Also set the ServerValidate event procedure to a server function that validates the data in a similar manner
------------------------------------
CLIENT VALIDATION FUNCTION
------------------------------------
<script language="jscript"
function ClientValidate(source, arguments
var strValue
strValue= arguments.Valu
if (IsNumeric(strValue)==true)
arguments.IsValid = true
return true
arguments.IsValid = false
return false
function IsNumeric(strString)
// check for valid numeric string
var strValidChars = "0123456789.-"
var strChar
var blnResult = true
if (strString.length == 0) return false
// test strString consists of valid characters listed abov
for (i = 0; i < strString.length && blnResult == true; i++)
strChar = strString.charAt(i)
if (strValidChars.indexOf(strChar) == -1)
blnResult = false
return blnResult
</script
------------------------------------
SERVER VALIDATION FUNCTIO
------------------------------------
Private Sub CustomValidator1_ServerValidate
(ByVal source As System.Object, ByVal args As
System.Web.UI.WebControls.ServerValidateEventArgs)
Handles CustomValidator1.ServerValidat
Dim strValue as strin
Tr
' Get value from ControlToValidate (passed as args
strValue = args.Valu
If IsNumeric(strValue) The
args.IsValid = Tru
Retur
End I
' Number is not Numeric, return False
args.IsValid = Fals
Retur
Catch ex As Exceptio
' If there was getting the value, return False
args.IsValid = Fals
Retur
End Tr
End Su
Hope this is of some help to you
PR