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.
- Change MyImage to derive from asp:ImageButton instead of asp:Image.
- Copy all the code from MyImage into a new MyClickImage and derive from asp:ImageButton.
- 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 :)