Is there a way to utilize glyphicons as icons for ASP Buttons
using C# instead of HTML?
Normally, you would apply the proper glyphicon
CSS to an <i>
element and then nest it under the desired button. But I want to accomplish this programmatically.
I attempted the following code without success:
HtmlGenericControl i1 = new HtmlGenericControl("i");
i1.Attributes["class"] = "glyphicon glyphicon-backward";
i1.Attributes["aria-hidden"] = "true";
Button btnFirst = new Button();
btnFirst.ID = "btnFirst";
btnFirst.CommandName = "FirstPage";
btnFirst.CssClass = "btn btn-default pageButton";
btnFirst.Click += new EventHandler(btnFirst_Click);
btnFirst.Controls.Add(i1);
container.Controls.Add(btnFirst);
When running the code above, the button appears but with no icon. There is also no nested <i>
element in the HTML source.