Ocean Ocean - 1 month ago 33
ASP.NET (C#) Question

How to use FontAwesome icons in asp.net webform ImageButton controls

I am planning to use FontAwesome icons in my asp.net webforms websites. The problem is that in many cases, the images are set dynamically from the code behind using asp:ImageButton using the ImageUrl property. Since FontAwesome uses either

<I>
or
<Span>
tags to display icons, I am wondering how to use it in asp:ImageButton . I am new to FontAwesome icons, so my apologies for this simple question

Answer

As FontAwesome is a font that requires HTML elements to display, neither <asp:ImageButton /> (only allows images) nor <asp:Button /> (only allows plain text) are suitable. You are better off using a HtmlButton.

HtmlButton Remarks: The HTML 4.0 <button> element enables you to create buttons composed of embedded HTML elements (and even other Web Forms controls).

<button id="btnSearch" runat="server"><i class="fa fa-search"></i> Search</button>

Read more: HtmlButton Control