Custom validation

Discussion in 'ASP .Net' started by Sam, Nov 10, 2003.

  1. Sam

    Sam Guest

    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
    Sam, Nov 10, 2003
    #1
    1. Advertising

  2. Sam

    Teemu Keiski Guest

    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

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist

    "Sam" <> wrote in message
    news:09cf01c3a7a7$0f414a60$...
    > 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
    >
    Teemu Keiski, Nov 10, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Colin Mackay
    Replies:
    0
    Views:
    2,672
    Colin Mackay
    Jun 25, 2003
  2. Libs
    Replies:
    0
    Views:
    1,479
  3. Colin Basterfield

    Web form validation vs object validation

    Colin Basterfield, Nov 28, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    417
    Tommy
    Nov 29, 2003
  4. Matt
    Replies:
    14
    Views:
    4,061
    Chad Z. Hower aka Kudzu
    Jan 30, 2004
  5. =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?=

    Using Summary Validation control with server Custom validation

    =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?=, Oct 15, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    868
    =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?=
    Oct 15, 2004
Loading...

Share This Page