Html 如何在 ASP.Net 中的 asp:Button 中放置 Bootstrap Glyphicon?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24285570/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I put a Bootstrap Glyphicon inside an asp:Button in ASP.Net?
提问by allence
I'm using Bootstrap 3 in my project, and I want to use Bootstrap Glyphicons in ASP.net buttons.
我在我的项目中使用 Bootstrap 3,我想在 ASP.net 按钮中使用 Bootstrap Glyphicons。
Here is the code I used, though it didn't work out (I got a sample which uses Twitter Bootstrap <span>
tags instead of <i>
tags):
这是我使用的代码,虽然它没有成功(我得到了一个使用 Twitter Bootstrap<span>
标签而不是<i>
标签的示例):
<asp:Button ID="btnRandom"
runat="server"
Text="<span aria-hidden='true'
class='glyphicon glyphicon-refresh'>
</span>"
onclick="btnRandom_Click" />
Maybe something extra should be done.
也许应该做一些额外的事情。
How can I get it to work? Thanks in advance for the replies.
我怎样才能让它工作?预先感谢您的答复。
回答by lucidgold
You have to use asp:LinkButtoninstead ofa asp:Button, here is how it works for me using Bootstrap 3in an ASP.NET web-application:
你必须使用ASP:LinkButton的,而不是一个ASP:按钮,在这里是如何工作的我使用引导3在ASP.NET Web应用程序:
From your code you can make the following work:
从您的代码中,您可以进行以下工作:
<asp:LinkButton ID="btnRandom"
runat="server"
CssClass="btn btn-primary"
OnClick="btnRandom_Click">
<span aria-hidden="true" class="glyphicon glyphicon-refresh"></span>
</asp:LinkButton>
Here is an example of what I use for a Submit Buttonwith text "Submit":
这是我用于带有文本“提交”的提交按钮的示例:
<asp:LinkButton ID="SubmitBtn"
runat="server"
CssClass="btn btn-primary"
OnClick="SubmitBtn_Click">
<span aria-hidden="true" class="glyphicon glyphicon-ok"></span>Submit
</asp:LinkButton>
回答by Mehdi Souregi
What is real use of ASP Server
control when you can do that in HTML
server control :
ASP Server
当您可以在HTML
服务器控制中执行此操作时,控制的真正用途是什么:
You can convert the HTML element to a server control by setting the runat="server" attribute.
您可以通过设置 runat="server" 属性将 HTML 元素转换为服务器控件。
<button runat="server" >
<span aria-hidden="true" class="glyphicon glyphicon-refresh"></span>Refresh
</button>
回答by Cubo Hayachi
try this
尝试这个
<button id="btnSubSearch" runat="server" type="submit" class="btn btn-default" onserverclick="btnSubSearch_Click">
<span aria-hidden="true" class="glyphicon glyphicon-search">
</span>
</button>
回答by zafer
You can use linkButton instead of button or asp:Button just like this;
您可以像这样使用 linkButton 而不是 button 或 asp:Button ;
<linkbutton runat="server"><a class="btn btn-info btn-md"> <span
class="glyphicon glyphicon-plus" style="font-size: x-large; font-weight:
bolder"></span> </a></linkbutton>
回答by abdol-hamid Hosseiny
its work for Asp:Buttonglyphicon style:
它适用于 Asp:Buttonglyphicon 样式:
<div class="btn btn-primary glyphicon glyphicon-search">
<asp:Button ID="Button1" runat="server" Text="Search" BackColor="Transparent" BorderWidth="0" OnClick="Button1_Click" />
</div>