Click to See Complete Forum and Search --> : asp.net button as image


esthera
09-08-2005, 02:27 AM
how can I change a button to show an image

<asp:button id="Button" runat="server" Width="121px" Text="Test"></asp:button>


should still be a button but show an image that i set.
what is the correct code for this?

Cstick
09-08-2005, 08:59 PM
<asp:imagebutton id="ImgButton" runat="server" src="path/to/image.gif" />

esthera
09-09-2005, 01:35 AM
it's strange -- if I use your code then I see the button but it doesn't work (process the code)

If I change the id to the id of my button then I get an error.
I'm very new to .net
What am I missing out on?

Cstick
09-09-2005, 08:39 PM
The event arguments for a normal button and an Image button are different. A button is like this:

Private Sub btnButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnButton.Click


And an image button is like this:

Private Sub btnImage_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnImage.Click


Since you are new, I'd recommend that you look at the tutorials section of www.asp.net, once you have gone through that and played with controls, code, etc. and become comfortable with .Net, then I'd recommend that you take a look at these sites. I'm sure that if you start a thread requesting good .Net websites, you'll get a bunch more good links.:
www.4guysfromrolla.com
www.codeproject.com
MSDN .Net Framework Reference:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netstart/html/cpframeworkref_start.asp

esthera
09-11-2005, 02:29 AM
hi thanks for your help

i changed the sub as you suggested -- I now see the button but nothing is happening when I click it. Any ideas?

Cstick
09-11-2005, 10:31 PM
Do you have your script on the same page as your html? If so, the html for the button should look something like this.

<asp:imagebutton id="btnImage" src="path/to/image.gif" onclick="btnImage_Click" runat="server" />

esthera
09-12-2005, 12:47 AM
it's on the page .aspx.vb behind my page.

I even tried putting a class to a regular button with an image but it ignored it.

Asp.net is really much different then asp i see.