Adding custom client-side onClick handler with client-side validator controls

Discussion in 'ASP .Net Web Controls' started by Zoe Hart, Jan 8, 2004.

  1. Zoe Hart

    Zoe Hart Guest

    I know that I can use a control's Attributes collection to specify
    client-side event handlers. I want to add a simple javascript function to
    pop up a confirmation message for a command button. The problem is that the
    page uses several client-side field validators so ASP.NET is already using
    the control's onClick event to call the validation logic. Is it possible to
    have a custom client-side handler when you're using the validator controls?
    The only way I've managed it in the past is to turn off client-side
    validation for the page, but I'd rather not do that in this situation where
    I'm making more extensive use of the client-side validators.

    Thanks,
    Zoe
     
    Zoe Hart, Jan 8, 2004
    #1
    1. Advertising

  2. The key is to add your code to the onClick event handler. You can acheive
    this using the "new Function" syntax in JavaScript. This is an example of
    something called a "higher order function" which is a function whose return
    value is yet another function. Here is the JavaScript that will enable this:

    function AddEventHandler (func, body) {
    if (func != null)
    return new Function(body + ';' + func.toString());
    else
    return new Function(body);
    }

    function AddOnClickEventHandler (ctrl, body) {
    ctrl.onclick = AddEventHandler(ctrl.onclick, body);
    }

    "Zoe Hart" <> wrote in message
    news:%...
    > I know that I can use a control's Attributes collection to specify
    > client-side event handlers. I want to add a simple javascript function to
    > pop up a confirmation message for a command button. The problem is that

    the
    > page uses several client-side field validators so ASP.NET is already using
    > the control's onClick event to call the validation logic. Is it possible

    to
    > have a custom client-side handler when you're using the validator

    controls?
    > The only way I've managed it in the past is to turn off client-side
    > validation for the page, but I'd rather not do that in this situation

    where
    > I'm making more extensive use of the client-side validators.
    >
    > Thanks,
    > Zoe
    >
    >
     
    Scott Wisniewski, Jan 8, 2004
    #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. giant food
    Replies:
    2
    Views:
    11,866
    Chris Jackson
    Dec 12, 2003
  2. Stephen Adam
    Replies:
    1
    Views:
    572
    Peter Blum
    Feb 22, 2005
  3. Lo?c Mah?
    Replies:
    3
    Views:
    678
    F. GEIGER
    Jul 22, 2004
  4. Lewis Holmes
    Replies:
    5
    Views:
    2,832
    Allen Chen [MSFT]
    Mar 18, 2009
  5. Hunpin Toh
    Replies:
    0
    Views:
    181
    Hunpin Toh
    Jul 3, 2003
Loading...

Share This Page