tags:

views:

6129

answers:

4

I have a image button. I wanted to add a text "Search" on it. I am not able to add it because the "imagebutton" property in VS 2008 does not have text control in it. Can anyone tell me how to add text to a image button??

  <asp:ImageButton ID="Searchbutton" runat="server" AlternateText="Search" 
        CssClass="bluebutton"
        ImageUrl="../Graphics/bluebutton.gif" Width="110px" 
        onclick="Searchbutton_Click"/>
+3  A: 
<button runat="server" 
  style="background-image:url('/Content/Img/stackoverflow-logo-250.png')" >
  your text here<br/>and some more<br/><br/> and some more ....
  </button>
leppie
+2  A: 

You can't do it with ImageButton.

But you can use simple Button, set text which you like and add background image (bluebutton.gif) using CSS.

Marek Blotny
A: 

I don't think you can write text to an ImageButton control of ASP.NET. You can generate image on the fly if that's what you need, and write the text from your code behind, but it will be too complicated, use normal button with CSS instead, unless your image cannot be generated by CSS.

Arief Iman Santoso
A: 

You can also do this using an asp:Label, like this:

<style type="text/css">
    .faux-button
    {
        cursor:pointer;
    }
</style>

<div class="faux-button">
    <asp:ImageButton ID="ibtnAddUser" runat="server" ImageUrl="~/Images/add.gif" AlternateText="Add a user image" />
    <asp:Label ID="lblAddUser" runat="server" Text="Add User" AssociatedControlID="imgClick" />
</div>
Khanzor