Raising a click event

G

Guest

I created a custom control - inheriting from WebControl.

How do I give this control a click event for the user of the control to put
some code behind? Thanks.

Jerry
 
G

Guest

To be more specific...

My custom control is made up of two images and a div. A click on either of
the images or the div should trigger the click event.
 
T

Teemu Keiski

Hi,

you'd need to implement IPostBackEventHandler interface, plus generate
script calls into onclick attributes of images and divs (is it div
containing two images? should it be distinct which one was clicked or just
the div is enough?)

You can make the script call with Page.GetPostBackEventReference (in ASP.NET
v2.0 it's Page.ClientScript.GetPostBackEventReference) and if you need to
distinguish between clicked elements, give that method an argument
indicvating which one was clicked.

When you implement IPostBackEventHandler interface, given argument is passed
there (e.g IPostBackEventHandler.RaisePostBackEvent is raised when the
element is clicked and postback script run) so you can raise your own event
from there.

Tell a bit more about the images and div, and I can give you a code sample.
Here's also a good stuff to look at

http://msdn.microsoft.com/library/d.../cpconReceivingPostbackEventNotifications.asp

http://msdn.microsoft.com/library/d...eneratingclient-sidejavascriptforpostback.asp
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top