如何在ASP.NET按钮中使用Twitter引导图标?

如何在ASP.NET按钮中使用Twitter引导图标?,asp.net,twitter-bootstrap,Asp.net,Twitter Bootstrap,如何使用: <i class="icon-etc"></i> 使用asp.net按钮?链接按钮,如下所示 <asp:LinkButton ID="SelectButton" runat="server" CssClass="btn btn-info"><i class="icon-ok icon-white"></i>&nbsp;Select</asp:LinkButton> 可以将标记作为值添加到LinkBu

如何使用:

<i class="icon-etc"></i> 

使用asp.net按钮?

链接按钮,如下所示

<asp:LinkButton ID="SelectButton" runat="server" CssClass="btn btn-info"><i class="icon-ok icon-white"></i>&nbsp;Select</asp:LinkButton>
可以将标记作为值添加到LinkButton文本属性中

e、 g

您甚至可以将其与侧边文本一起使用

e、 g

我是这样做的

标记:

<asp:PlaceHolder ID="phButtonToLabelsAdminBox" runat="server"></asp:PlaceHolder>
<asp:Button ID="btnSave" runat="server" CssClass="btn" Text="Spara" />
<asp:Button ID="btnClear" runat="server" CssClass="btn" Text="Töm/Ny" />
以及小组:

Private Sub FixGlyph(ph As PlaceHolder, btn As Button, IconClass As String, Optional CustomLabelStyle As String = "")

If btn.Visible = False Then Exit Sub
Dim g As New HtmlGenericControl
g.ID = "labelFor_" + btn.ID
g.TagName = "label"
g.Attributes.Add("for", btn.ClientID)
g.Attributes.Add("class", "" + btn.CssClass + "")
If Not CustomLabelStyle = "" Then g.Attributes.Add("style", CustomLabelStyle)
g.InnerHtml = "<i class=""" + IconClass + """></i> " + btn.Text
ph.Controls.Add(g)
btn.Attributes.Add("style", "display:none;")

End Sub

我在标记中使用普通的asp:Button,唯一的事情是在其他可能为按钮设置visible true/false的代码之后运行FixGlyph,并按照希望按钮出现的顺序添加FixGlyph。除此之外,它还适用于我。

谢谢Anders Smedman,你的代码确实起到了作用。 这是C代码,如果有人需要的话

 private void FixGlyph(PlaceHolder ph, Button btn, string iconClass, string customLabelStye = "")
    {
        if (btn.Visible)
        {
            var g = new HtmlGenericControl();
            g.ID = "labelFor_" + btn.ID;
            g.TagName = "label";
            g.Attributes.Add("for",btn.ClientID);
            g.Attributes.Add("class","" + btn.CssClass +"");
            if (customLabelStye != "")
            {
                g.Attributes.Add("style",customLabelStye);
            }
            g.InnerHtml = "<i class='" + iconClass + "'></i> " + btn.Text;
            ph.Controls.Add(g);
            btn.Attributes.Add("style","display:none;");
        }

    }
试试这个

<asp:LinkButton ID="btnExample" runat="server" Text="<span class='glyphicon glyphicon-repeat'></span> Button" CssClass="btn btn-primary btn-xs" OnClick="btn_Click"></asp:LinkButton>


关于C:

这是最好的答案,只是永远不要去想它!感谢您记忆中使用asp:LinkButton和不使用asp:Button前者有效,后者无效。抓住我;我发现在gridview选择按钮中使用I类最有用。我使用这种方法是因为我需要能够从后面的代码中更改文本和图标。但是,我想补充一点,为了使它能够工作,我必须将元素的类名用一个倒逗号括起来,即大家都注意到的@philip stratford,谢谢!刚刚更新它以匹配您的建议。@Korv,我建议选择一个最佳答案,这是一个好答案如果其中一个答案解决了您的问题,请选择正确答案。
Private Sub FixGlyph(ph As PlaceHolder, btn As Button, IconClass As String, Optional CustomLabelStyle As String = "")

If btn.Visible = False Then Exit Sub
Dim g As New HtmlGenericControl
g.ID = "labelFor_" + btn.ID
g.TagName = "label"
g.Attributes.Add("for", btn.ClientID)
g.Attributes.Add("class", "" + btn.CssClass + "")
If Not CustomLabelStyle = "" Then g.Attributes.Add("style", CustomLabelStyle)
g.InnerHtml = "<i class=""" + IconClass + """></i> " + btn.Text
ph.Controls.Add(g)
btn.Attributes.Add("style", "display:none;")

End Sub
 private void FixGlyph(PlaceHolder ph, Button btn, string iconClass, string customLabelStye = "")
    {
        if (btn.Visible)
        {
            var g = new HtmlGenericControl();
            g.ID = "labelFor_" + btn.ID;
            g.TagName = "label";
            g.Attributes.Add("for",btn.ClientID);
            g.Attributes.Add("class","" + btn.CssClass +"");
            if (customLabelStye != "")
            {
                g.Attributes.Add("style",customLabelStye);
            }
            g.InnerHtml = "<i class='" + iconClass + "'></i> " + btn.Text;
            ph.Controls.Add(g);
            btn.Attributes.Add("style","display:none;");
        }

    }
<asp:LinkButton ID="btnExample" runat="server" Text="<span class='glyphicon glyphicon-repeat'></span> Button" CssClass="btn btn-primary btn-xs" OnClick="btn_Click"></asp:LinkButton>
<asp:LinkButton ID="btnExample" runat="server" Text="<i class='glyphicon glyphicon-flash'></i> Button" CssClass="btn btn-primary btn-xs" OnClick="btn_Click"></asp:LinkButton>