How to use a Twitter Bootstrap icon inside an ASP.NET Button?

后端 未结 5 1757
感动是毒
感动是毒 2021-02-04 09:22

How can I use a:

 

with an asp.net button?

5条回答
  •  梦谈多话
    2021-02-04 09:38

    I have done like this.

    Markup:

    
    
    
    

    CodeBehind Page_Load()

    FixGlyph(phButtonToLabelsAdminBox, btnSave, "icon-ok")
    FixGlyph(phButtonToLabelsAdminBox, btnClear, "icon-refresh")
    

    And the Sub:

    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 = " " + btn.Text
    ph.Controls.Add(g)
    btn.Attributes.Add("style", "display:none;")
    
    End Sub
    

    I use ordinary asp:Button in my Markup and the only things are that to run the FixGlyph after other code that might set visible true/false for the buttons and to add the FixGlyph in the order you want the buttons to appear. Other than that, it works for me.

提交回复
热议问题