Reputation: 343
I have a HTML button which has an icon inside the button.
HTML of button:
<button type="submit" class="btn blue"><i class="fa fa-check"></i>Save</button>
I need to be able to put this <i>
code inside a button that I generate within ASP.NET. This is the code to make the button.
Button button = new Button();
button.Id = "btnSave";
button.CssClass = "btn blue";
button.Text = "Save";
Placeholder.Controls.Add(button);
I saw a solution on stackoverflow, but that is for LinkButtons.
Upvotes: 1
Views: 3687
Reputation: 8492
You can use the character code to add the font-awesome icon to the button text directly.
button.CssClass = "fa";
button.Text = Server.HtmlDecode(" Save");
Upvotes: 0
Reputation: 35514
You can use the normal button if you add runat="server"
with onserverclick
<button type="submit" class="btn blue" runat="server" onserverclick="Button1_Click">
<i class="fa fa-check"></i>Save
</button>
Dyamically generated
HtmlButton hb = new HtmlButton();
hb.ServerClick += Button1_Click;
hb.Attributes.Add("class", "btn blue");
hb.InnerHtml = "<i class=\"fa fa-check\"></i>Save";
PlaceHolder1.Controls.Add(hb);
Upvotes: 1