Image on a button

Discussion in 'ASP .Net Web Controls' started by Jimmy D, Nov 23, 2004.

  1. Jimmy D

    Jimmy D Guest

    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?
     
    Jimmy D, Nov 23, 2004
    #1
    1. Advertising

  2. 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]


    "Jimmy D" <> wrote in message
    news:...
    > 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?
     
    Ken Cox [Microsoft MVP], Nov 24, 2004
    #2
    1. Advertising

  3. Jimmy D

    Jimmy D Guest

    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.
     
    Jimmy D, Nov 25, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Purvi T
    Replies:
    0
    Views:
    935
    Purvi T
    Oct 19, 2004
  2. Russell
    Replies:
    3
    Views:
    6,972
    Lau Lei Cheong
    Jun 24, 2004
  3. James Storey via JavaKB.com
    Replies:
    7
    Views:
    11,578
  4. Laszlo Zsolt Nagy
    Replies:
    1
    Views:
    1,436
    Kartic
    Jan 26, 2005
  5. Chicagoboy27

    image button as a back button

    Chicagoboy27, Oct 26, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    2,045
    Chicagoboy27
    Oct 30, 2006
Loading...

Share This Page