views:

196

answers:

2

I got this logic in a control to create a correct url for an image. My control basically needs to diplay an image, but the src is actually a complex string based on different parameters pointing at an image-server.

So we decided to to create a control MyImage derived from asp:Image - it works like a charm. Now i need the same logic but my image now needs to respond to a click. What i mean is - the 'MyImage' is used to display images on the site but in a few rare cases i would like it to be clickable.

I think i got three choices.

  1. Change MyImage to derive from asp:ImageButton instead of asp:Image.
  2. Copy all the code from MyImage into a new MyClickImage and derive from asp:ImageButton.
  3. Wrap logic on MyImage to add a hyperlink, implement IPostbackHandler for that hyperlink and add the logic to handle the event.

Obviously i would very much like to avoid using option 2) since i would have to maintain two almost identically controls. The problem with option 1) as i see it (perhaps i'm wrong?) Is that all the images on the site that are not supposed to be clickable will automaticly become clickable. Option 3) seems overly complicated as i would have to maintain state, events and building the link manually.

I'm looking for a quick answer like 'you're stupid, just set property 'x' to false when you don't want it to be clickable' - but if i'm not mistaking it is not that obvious and ofcourse a more elaborate answer would be fine :)

EDIT: Added the 3rd option - i forgot to put that there in the first place :)

A: 

I would avoid the whole derivation business completely and just add a JavaScript onclick parameter to my image when needed.

I don't know what a click is going to do in your page, but I guess it can be done utilizing client side JavaScript.

Tomalak
I need a postback to handle the logic serverside, and i want it to be part of the asp.net postback-flow, not an ajax call etc. :)
Per Hornshøj-Schierbeck
A: 

Gah ok 'im stupid, i just have to set enabled = "false" if i don't want it to be clickable. I think they should have used another name but 'enabled' since it has other meaning on other controls.

Per Hornshøj-Schierbeck