Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Controls (http://www.velocityreviews.com/forums/f63-asp-net-web-controls.html)
-   -   Adding custom client-side onClick handler with client-side validator controls (http://www.velocityreviews.com/forums/t772242-adding-custom-client-side-onclick-handler-with-client-side-validator-controls.html)

Zoe Hart 01-08-2004 09:36 PM

Adding custom client-side onClick handler with client-side validator controls
 
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 01-08-2004 10:45 PM

Re: Adding custom client-side onClick handler with client-side validator controls
 
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" <Zoe.Hart.NoSpam@Competitive.com> wrote in message
news:%23wUAs9i1DHA.1272@TK2MSFTNGP12.phx.gbl...
> 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
>
>





All times are GMT. The time now is 03:14 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.