Last post Apr 23, 2008 10:47 AM by notken
Apr 23, 2008 10:01 AM|notken|LINK
Hi there. Sorry if this has been covered before but I couldn't find any reference to it.
I have a user control which is based on an asp.net image control. One of the custom properties allows you to make the image 'clickable', which I would like to do by surrounding the custom image tag with a hyperlink (although also have an option to make it
a linkbutton eventually).
I've tried a couple of ways, and neither has quite worked:
* Overriding the render method, and rendering the begin and end tags of a new hyperlink control right before and just after rendering the base control. This worked fine except that it ignored the rest of a template that I'd allowed to be defined for this
user control (for various reasons). Incidentally, if I didn't elect to hyperlink the control, the full template was rendered correctly.
* In the onload method, trying to add a new hyperlink to the parent control, and changing the parent of the user control to this new hyperlink. I wasn't entirely expecting this to work, and it didn't! (It complains that "The control collection cannot
be modified during DataBind, Init, Load, PreRender or Unload phases.".)
Code for the first test is:
HyperLink hyperLink = new HyperLink();
For the second I tried:
Should that be the other way around (getting a reference to the Parent first), or should I just be doing this in another event? Or am I trying something insane that can be achieved much better?
Thanks so much for your time.
Apr 23, 2008 10:29 AM|whatispunk|LINK
Couldn't you just inherit from ImageButton?
Apr 23, 2008 10:47 AM|notken|LINK
Thanks for your feedback, but not really, for a few reasons:
I appreciate your thoughts, though.