views:

155

answers:

6

I want to add an image, instead of the default button.

I already have a CSS class for the image, will this work?

<asp:Button ID="..." CssClass=""/>

I am trying it now, and the image is all scrunched up. Maybe it's a CSS issue?

A: 

Yes, you can do this, just be sure to set the width and height of the class in your CSS to prevent the scrunching

Mitchel Sellers
+4  A: 

Why not use an ImageButton control?

Tim S. Van Haren
I'm styling an existing app, it has events tied to it already etc.
Blankman
Use an image button with the same name as your button and it will pick up all of the events.
orandov
actually no it won't, += new Eventhandler breaks, have to use ImageClickEventhandler
Blankman
I went with the imagebutton, button image looked funny when clicked.
Blankman
+1  A: 

Although you can "replace" a button with an image using the following CSS...

.className {
   background: url(http://sstatic.net/so/img/logo.png) no-repeat 0 0;
   border: 0;
   height: 61px;
   width: 250px
}

...the best thing to do here is use an ImageButton control because it will allow you to use alternate text (for accessibility).

Josh Stodola
A: 

Assuming a Css class of "image" :

input.image { 
  background: url(/i/bg.png) no-repeat top left; 
  width: /* img-width */; 
  height: /* img-height */ 
}

If you don't know what the image width and height are, you can set this dynamically with javascript.

Atømix
A: 

I actually prefer to use the html button form element and make it runat=server. The button element can hold other elements inside it. You can even add formatting inside it with span's or strong's. Here is an example:

<button id="BtnSave" runat="server"><img src="Images/save.png" />Save</button>
Banzor
A: 

Try this?

<asp:ImageButton src="image.gif" id="blah" runat="server" AlternateText="Button" />
Django Reinhardt