Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding an image and text both in asp.net button

I am looking for a solution where I will be able to add an image and text both in asp.net button.

 <asp:Button ID="Button1" runat="server" Text="Button"/> 

I am only able to specify text to the button, but how can I add an image as well to it?

like image 815
Arry Avatar asked Jul 28 '13 20:07

Arry


People also ask

How can add image in button in asp net?

Step 1 – Open the Visual Studio –> Create a new empty Web application. Step 2 – Create a New web page for display Imagebutton on it. Step 3 – Drag and drop ImageButton control on web page from Toolbox. Step 4 – Set ImageUrl property of ImageButton Control for display image on control.

What is difference between image and image button?

ImageButtons has push states, where as a clickable image does not. You also can't call setText for ImageButton, you can with a regular button. They all derive from view, but looking at the following extends chain may help a little. Funny.

How can add image in web form in asp net?

To upload the image, click on Choose File and then browse to the image which you want to upload. Once the image is selected then the name of the image will be displayed next to the Choose File button as shown in the following screenshot.


2 Answers

By default, ASP .Net doesn't have a button which can render both image and text at the same time. However, you can achieve in two ways.

Using CSS

I prefer CSS because it is light weight, and you can style it whatever you want.

enter image description here

<style type="text/css">
    .submit {
        border: 1px solid #563d7c;
        border-radius: 5px;
        color: white;
        padding: 5px 10px 5px 25px;
        background: url(https://i.stack.imgur.com/jDCI4.png) 
            left 3px top 5px no-repeat #563d7c;
    }
</style>

<asp:Button runat="server" ID="Button1" Text="Submit" CssClass="submit" />

Third Party Control

It works right out of the box. However, you cannot change their style easily.

enter image description here

Use third party control like Telerik RadButton.

Last but not least if you want, you can implement a custom server control by yourself.

like image 57
Win Avatar answered Sep 21 '22 06:09

Win


Here is a simple Solution, that works for me:

 <asp:LinkButton runat="server" ID="btnRun" Text="<i class='fa fa-home'></i> Search"
                                    CssClass="btn-success" />
like image 28
Meysam Chegini Avatar answered Sep 23 '22 06:09

Meysam Chegini