PC Review


Reply
Thread Tools Rate Thread

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

 
 
Zoe Hart
Guest
Posts: n/a
 
      8th Jan 2004
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


 
Reply With Quote
 
 
 
 
Scott Wisniewski
Guest
Posts: n/a
 
      8th Jan 2004
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET, adding controls on client side Oleg Ogurok Microsoft ASP .NET 2 22nd Apr 2006 01:02 AM
How do I use client-side validation with a custom validator? Alan Silver Microsoft ASP .NET 2 2nd Nov 2005 08:03 PM
No client side script generated by custom validator Stephen Adam Microsoft ASP .NET 1 22nd Feb 2005 06:35 PM
How to ref web form controls in client side event handler? Eric Microsoft ASP .NET 3 9th Nov 2004 01:22 PM
custom client-side onClick events for asp:button giant food Microsoft ASP .NET 2 12th Dec 2003 08:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:48 AM.