Ocean Ocean - 8 months ago 201
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

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


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