Inherit from ImageButton, add text property

M

MarkMurphy

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?

Thanks,

Mark
 
S

Steven Cheng[MSFT]

Hi Mark,

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:

<input type="image" name="ImageButton1" id="ImageButton1"
src="http://msdn.micros
oft.com/library/toolbar/3.0/images/banners/msdn_masthead_ltr.gif"
border="0" />

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?

Above are some of my suggestions. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
M

MarkMurphy

Hi Steven,

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.

-Mark
 
S

Steven Cheng[MSFT]

Hi Mark,

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:


#Serving Dynamic Content with HTTP Handlers
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html
/httphandl.asp

#HTTP Handlers for Images in ASP.NET
http://www.c-sharpcorner.com/Code/2003/June/HTTPHandlersForImages.asp

#An ASP.NET thumbnail solution
http://www.codeproject.com/aspnet/thumbtools.asp


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).


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
S

Steven Cheng[MSFT]

Hi Mark,

Have you had a chance to check out the suggestions in my last reply or have
you got any further ideas on this issue? If there're anything else we can
help, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top