10

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?

6

4 Answers 4

26

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.sstatic.net/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.

Sign up to request clarification or add additional context in comments.

2 Comments

thank you very much! At least we have some control over .net :/ Dont like using Telerik:)
this is helpful. But you also need to add additional property background-repeat:repeat-y; to make image look at left and not repeat
5

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" />

Comments

2

Here is a simple Solution, that works for me:

<asp:LinkButton ID="ClickMe" runat="server" Text="Click Me" OnClick="ClickMe_Click" style="text-decoration: none; color: #505050;">
    <asp:Image runat="server" ImageUrl="/Resources/Bitmaps/excel_24.png" style="margin-left:5px;" />
</asp:LinkButton>

Comments

1

You can also use a font icon instead of an image.

CSS

.button {
   min-width:175px;
   border-radius:50px;
   background:none;
   outline:none;
   border:none;
   color:#fff;
   padding:15px 25px;
   margin-top:10px;
   background: rgba(115,84,178,1);
   background: -moz-linear-gradient(45deg, rgba(115,84,178,1) 0%, rgba(115,84,178,0.95) 34%, rgba(115,84,178,0.95) 35%, rgba(96,107,192,0.91) 62%, rgba(84,160,231,0.85) 100%);
   background: -webkit-gradient(left bottom, right top, color-stop(0%, rgba(115,84,178,1)), color-stop(34%, rgba(115,84,178,0.95)), color-stop(35%, rgba(115,84,178,0.95)), color-stop(62%, rgba(96,107,192,0.91)), color-stop(100%, rgba(84,160,231,0.85)));
    background: -webkit-linear-gradient(45deg, rgba(115,84,178,1) 0%, rgba(115,84,178,0.95) 34%, rgba(115,84,178,0.95) 35%, rgba(96,107,192,0.91) 62%, rgba(84,160,231,0.85) 100%);
    background: -o-linear-gradient(45deg, rgba(115,84,178,1) 0%, rgba(115,84,178,0.95) 34%, rgba(115,84,178,0.95) 35%, rgba(96,107,192,0.91) 62%, rgba(84,160,231,0.85) 100%);
    background: -ms-linear-gradient(45deg, rgba(115,84,178,1) 0%, rgba(115,84,178,0.95) 34%, rgba(115,84,178,0.95) 35%, rgba(96,107,192,0.91) 62%, rgba(84,160,231,0.85) 100%);
    background: linear-gradient(45deg, rgba(115,84,178,1) 0%, rgba(115,84,178,0.95) 34%, rgba(115,84,178,0.95) 35%, rgba(96,107,192,0.91) 62%, rgba(84,160,231,0.85) 100%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#7354b2', endColorstr='#54a0e7', GradientType=1 );
}

You can remove the background and filter part in the class button in the above style. I just used it for the gradient background for the button.

HTML

<button runat="server" id="btnDownload" class="button" onserverclick="clickEvent">
    <i class="fa fa-download" style="font-size:20px;float:left;"></i> DOWNLOAD
</button>

Button looks like below.

enter image description here

Fiddle demo here

And even you can change the icon color by just adding color to the <i>...</i>. Something like below.

<button runat="server" id="btnDownload" class="button" onserverclick="clickEvent">
    <i class="fa fa-download" style="font-size:20px;float:left;color:#ff4444;"></i> 
        DOWNLOAD
</button>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.