Image on a button

J

Jimmy D

In html I can create a button control that shows an image rather than
text through the use of button tags:

<button><img src="image.jpg"></button>

I want to create the same type of control in ASP.NET. I don't want to
have to specify four different images (onmouseover, onmouseout,
onmousedown and onmouseup) just to create an image that behaves like a
button. I want to be able to use the existing asp.net button control
(or an extension of that control) and specify an image rather than set
the text property, but have it behave like a regular asp.net button
(postback, etc). Is it just me or does this seem like fairly simple
functionality that's missing from ASP.NET?

Can this be done?
 
K

Ken Cox [Microsoft MVP]

Hi Jimmy,

You can use the ASP.NET imagebutton control for that. When the page loads,
add your mouseover/out events as JavaScript using the Attributes.Add method:

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
ImageButton1.Attributes.Add _
("onmouseover", "this.src='http://www.gc.ca/images/francaisbt.gif'")
ImageButton1.Attributes.Add _
("onmouseout", "this.src='http://www.gc.ca/images/englishbt.gif'")
End Sub

<asp:imagebutton id="ImageButton1" runat="server"
ImageUrl="http://www.gc.ca/images/englishbt.gif"></asp:imagebutton>

Does this help?

Ken
Microsoft MVP [ASP.NET]
 
J

Jimmy D

Hi Ken

Thank you - your answer was helpful. Unfortunately I was looking for
something that didn't involve using more than one image or having to
swap images using javascript. Ideally I'd like there to be an image
property on the ASP.NET button control, but it doesn't look like it'll
be that easy based on what I've read. Too bad, too, because I always
found it handy to be able to put an image right on an html button.

Thanks again for your reply.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top