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?
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.
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.
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.
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.
I prefer CSS because it is light weight, and you can style it whatever you want.
<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" />
It works right out of the box. However, you cannot change their style easily.
Use third party control like Telerik RadButton.
Last but not least if you want, you can implement a custom server control by yourself.
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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With