Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a user control that I used to create a button control with. It doesn't inherit from button. This control is composed of 3 buttons.I need to run a script on client click of this control to run some javascript. This "button" control has a clicked event generated during runtime through delegates. Is it possible to add an OnClientClick event to this user control or any other user control in general?

Thanks for your help
Posted

The OnClientClick just handles the javascript click event, and if it returns false, does not do a postback. If your control is not derived from a control that offers this, you can certainly handle a click event, if your control gets one on the client side, and I believe there's a boolean you can set that will stop postback, you'll need to trawl through the code generated by ASP.NET to work out a solution, or google for it.
 
Share this answer
 
Comments
CS1401 5-Jul-11 4:36am    
its very useful. thanks Chris..
I would suggest you to expose a new property like 'OnClientClickCustom' in yor user control. Have a get/set in it where you can handle the value you will set for this property.

Whil setting the value assigned, you can attach OnClientClick property to individual buttons. Also, any other Javascript event using controls Attribute.
This should do!
 
Share this answer
 
Comments
Member 10001361 18-Dec-13 4:36am    
can you share the code please.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900