allence allence - 1 year ago 1187
HTML Question

How do I put a Bootstrap Glyphicon inside an asp:Button in ASP.Net?

I'm using Bootstrap 3 in my project, and I want to use Bootstrap Glyphicons in buttons.

Here is the code I used, though it didn't work out (I got a sample which uses Twitter Bootstrap

tags instead of

<asp:Button ID="btnRandom"
Text="<span aria-hidden='true'
class='glyphicon glyphicon-refresh'>
onclick="btnRandom_Click" />

Maybe something extra should be done.

How can I get it to work? Thanks in advance for the replies.

Answer Source

You have to use asp:LinkButton instead of a asp:Button, here is how it works for me using Bootstrap 3 in an ASP.NET web-application:

From your code you can make the following work:

<asp:LinkButton ID="btnRandom" 
            CssClass="btn btn-primary"    
    <span aria-hidden="true" class="glyphicon glyphicon-refresh"></span>

Here is an example of what I use for a Submit Button with text "Submit":

<asp:LinkButton ID="SubmitBtn" 
                CssClass="btn btn-primary"    
    <span aria-hidden="true" class="glyphicon glyphicon-ok"></span>Submit
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download