Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font awesome inside asp button

This is my asp:button code which is not rendering font awesome's icon but instead shows the HTML as it is:

  <asp:Button runat="server" ID="btnRun" Text="<i class='icon-camera-retro'></i> Search" ValidationGroup="edt" OnClick="btnRun_Click"  CssClass="greenButton"/> 

Any idea how can I solve this issue?

like image 592
Jack Avatar asked Feb 25 '13 09:02

Jack


People also ask

How to add icon to asp button?

Adding icon in Button For example, you can render the desired icon in the button by using the following table that contains the listed icons' CSS class names in the “PrefixIcon” property of button component. Also, use “ContentType” property to display the icon in the button.

How do I use font awesome icons in Visual Studio?

Solution: First, open the extensions sidebar ( Ctrl+Shift+X ) and search for "font awesome auto" to locate and install the extension. When the installation is complete, the function will be activated immediately. Type "fa-" in your HTML file, and the auto-complete menu will be displayed.


1 Answers

You can't with the default asp.net button you will need to use a HTML button and give it runat=server attribute:

<button runat="server" id="btnRun" class="btn btn-mini" title="Search">     <i class="icon-camera-retro"></i> Search </button> 

So use code behind with this you add:

onserverclick="functionName"  

To the button, then in your C# do:

protected void functionName(object sender, EventArgs e) {     Response.Write("Hello World!!!"); } 

So final button looks like:

<button runat="server" id="btnRun" onserverclick="functionName" class="btn btn-mini" title="Search">     <i class="icon-camera-retro"></i> Search </button> 
like image 172
Ryan McDonough Avatar answered Sep 19 '22 15:09

Ryan McDonough