Custom validation

  • Thread starter Thread starter Sam
  • Start date Start date
S

Sam

Hi,

I have 3 separate server side textboxes (asp:textbox) for
US Phone. Now I want to do following:

1. Create a clientside javascript "ValidatePhone()". that
is not a problem.

2. Call this javascript when user clicks submit button in
aspx page. There are other requiredfield and
regularvalidation controls are there.

I am unable to figure out that
(a) From where AND
(b) How
should I call this function..

Thanks in advance
-Sam
 
Hi,

note that Page framework executes client-side validation by calling
Page_ClientValidate(). Trick is to take reference to the old
Page_ClientValidate into separate variable and then replace the old
Page_ClientValidate with our own method which is fired when page calls
Page_ClientValidate. This new method also calls the previously referenced
old Page_ClientValidate to execute "normal" validation.

function NewPageClientValidate()
{
//execute original validation
origValidate();
//Now run our custom code
ValidatePhone();
}

var origValidate;

//reference to original method
origValidate=Page_ClientValidate;

//replace with new method
Page_ClientValidate=NewPageClientValidate;

Note that you could use CustomValidator as well. More information about that
and ASP.NET Validation generally:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/aspplusvalid.asp
 
Back
Top