Custom validation

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
 
T

Teemu Keiski

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top