从后面的代码向HTML5按钮添加图标类

时间:2019-05-15 15:43:00

标签: c# css asp.net html5

我有一个HTML5按钮,我正在使用它作为SAVE / CREATE按钮,并且根据情况从后面的代码中更改了文本。这里没有问题,但是我需要从后面的代码中向我的按钮添加图标样式元素,这是行不通的:

set Main Group Group1 
Main Grpup is Group1 and its sub group is Group1_Sub1 
Main Grpup is Group1 and its sub group is Group1_Sub2 
set Main Group Group2 
Main Grpup is Group2 and its sub group is Group2_Sub1 
set Main Group Group3  
Main Grpup is Group3 and its sub group is Group3_Sub1 
Main Grpup is Group3 and its sub group is Group3_Sub2 

我正在尝试更改文本,并从背后的代码中添加一个字体真棒图标,如下所示:

<button typeof="button" id="btnSaveCreate" class="btn btn-danger" runat="server" onserverclick="btnSaveCreate_ServerClick"><i class="fas fa-road"></i></button>

那是行不通的,这也不行:

btnSaveCreate.InnerText = "Save <i class=\"fas fa-road\"></i>";

1 个答案:

答案 0 :(得分:0)

您可以使用<asp:Button>(经过测试并可以正常工作)

<asp:Button typeof="button" id="btnSaveCreate" runat="server"></asp:Button>

并使用字符代码在后面的代码中设置图标

btnSaveCreate.CssClass = "fas";
btnSaveCreate.Text = Server.HtmlDecode("Save &#xf018;");

或者,正如您所说(也已通过测试并可以正常工作):

<button typeof="button" id="btnSaveCreate" class="btn btn-danger" runat="server"></button>

及其背后的代码:

btnSaveCreate.Attributes.Add("class", "fas");
btnSaveCreate.InnerText = Server.HtmlDecode("Save &#xf018;");