Inherit from ImageButton, add text property

I started searching google, thinking there must be some sample code
about for adding a text property to an ImageButton so that one could
easily localize the button. After thinking about it though, I'm
guessing that one must dynamically generate the image with the text
embedded. Using other various methods might not yield a button-like
behavior when rendered.

Has anyone created a user control that acts like an image button with
a text property?

Advertisements

AS for the adding a Text Property for the ImageButton. I think you can
consider the following means:
1. Define a own custom ImageButton control which derived from the
ImageButton but it has a TExt property itself and will set the ParentClass
(ImageButton)'s ImageUrl depend on this "Text" property.

2. Build a simple ASP.NET Render control and output the ImageButton's html
source directly. The ImageButton control infact will be output as the
following html source:

You can directly render out the above things in the control's render method
and if you want to add a property to contorl the ImageUrl, it's also simple
to change the "src" attribute as you like. Do you think so?

Advertisements

Thanks. I was wanting the text property to contain text to be written
on top of the image. Font properties would be needed as well of
course. I guess the first question is how would look in HTML. Once
that is determined, the server control just needs to do the rendering.

Alternately, I wonder if it might be easier to generate custom GIFs
with the text dynamically added at request time. I guess and
HTTPModule would be the method here.

Thanks for your followup. From the further description in your last reply,
it seems that what you want is a new dynamically generated Image which also
contains a certain Text you set in the control's property, yes?

If so, I think the first thing is making a ImageGenerator which can
generate a new Image resource dynamically at runtime. Generally, we can
use HttpHandler to provide such a Image Generator which use the GDI+ apis,
here are some tech articles maybe helpful to you:

Then, you register this Image Handler in your web application and in your
custom ImageButton control, set the ImageUrl as the dynamic generate
Image's url( the url that request the Image handler which return an Image
stream).

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!