Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jul 24, 2010 07:05 AM by rugved_mandrekar
Feb 25, 2008 05:02 PM|LINK
Although the WebForm Designer doesn't display it properly, you can legitimately (as in, without errors) put an <asp:image control inside a <asp:linkbutton control using the source view. It will generate valid HTML consisting of an anchor link <a with an
image <img inside it. Of course you don't have much control over where the text goes in relation to the image (the image comes after if you use the Text= attribute), but you can control that further if you place the text between the tags. The biggest caveat
being that if you set the Text property from the code-behind, you also loose the image. But then, you can also put a <asp:literal or equivalent control inside the <asp:linkbutton and this gives you control over position and the text literal via code-behind
(again, just don't set the Text= attribute of the <asp:linkbutton).
Hopefully this helps others who read this as I'm sure you've figured something out by now.
Apr 03, 2008 06:57 AM|LINK
It is not working in Mozilla Fire Fox
Jul 17, 2008 06:53 PM|LINK
Yes dotnetslave's solution is topnotch. Worked for me in IE and Firefox too. Thankyou.
Apart from finding Photoshop's Text tool to be very poor, my reason for needing this is because I am creating a CMS in which my customers will be creating their own buttons, therefore I need to apply text to a button programmatically, and I didn't fancy
having to use big ugly default buttons.
Dec 04, 2008 11:07 AM|LINK
Have you had the answer for this yet?
because I am doing a very similar thing.
The link button with css class looks good enough to me.
even tried it and it works, But i really need a BUTTON which can have an IMAGE in the background, and still LOOK LIKE BUTTON.
Dec 04, 2008 04:17 PM|LINK
Here's a toolbar with the buttons I've created:
Note: Since I control the appearance of both the enabled and disabled state of each button, I can make the button look anyway I wish.
Nov 29, 2009 12:03 PM|LINK
Much later, but facing a similar issue:
I had automatically assumed that a LinkButton with its CSS background-image set was the way to go, but now IE6 is rendering my linkbutton as a Button (the little grey guy with the 3D look) and not showing the background image.
Dec 09, 2009 08:06 AM|LINK
i also came across same situation, i placed a button, then linked it to a css with background, but its not showing the image.
Jan 05, 2010 09:44 PM|LINK
<asp:LinkButton ID="lbtnAddNew" runat="server"><asp:Image ID="Image1" runat="server" ImageUrl="~/Images/add.png" /> Add Item</asp:LinkButton>
It's not that hard....
ASP.net VS HTML
Jan 06, 2010 02:20 AM|LINK
Sorry that I didn't post this earlier. And yes, you're right. The issue had been that we used a Button with an image for the background in CSS, which renders as expected in Firefox and possibly in IE8, but as a button in IE7. ImageButton works fine in both.
The only thing to watch out for is using a ButtonField of type Image in a gridview; in IE7 (and possibly other IEs), this causes a double postback for RowCommand when the user clicks on the button.
Jan 06, 2010 03:34 AM|LINK
1. You want to add back-ground image to button
2. You want just Image button
1. you can use css to add back-ground image to button
<asp:Button ID="btnTest" CssClass="BlueButton" Text="Submit"/>
Define .BlueButton CSS in any Css file or add in <style> tag of page. Make sure that image exists at specified location.
<asp:ImageButton ID="imgbtnTest" runat="Server" ImageUrl="~/images/demoButton.gif" />