How to have html in Text attribute of asp Button

Viewed 40768

I'm trying to include an <i> for the Text attribute for an asp button but it's just rendering the html as text...

<asp:Button runat="server" ID="modify" ToolTip="Modify" CssClass="btn btn-mini" OnClick="modify_Onclick" Text='<i class="icon-edit"></i>' />

I've got to be over thinking this...

EDIT: I'm using the twitter bootstrap framework. That's why the <i> tag. Here's an example: http://twitter.github.com/bootstrap/base-css.html#icons

8 Answers

You can exploit the <label> tag's for attribute. Basically any click on <label> will also fire the click event of a html element with an id same as <label>'s for attribute

For example:

<label for="modify"><i class="icon-edit"></i></label>
<asp:Button style="display:none;" runat="server" ID="modify" ToolTip="Modify" CssClass="btn btn-mini" OnClick="modify_Onclick" Text='' />

clicking the <label> element here(which clicks the <i> element too), will fire the <asp:button>'s click event.

I've tried to render html inside a button on the client side, I didn't want it to be using runat="server" so what I did was using javascript:

document.getElementById('button_<%= this.id %>').innerHtml = '<i class="fa fa-edit"></i>';
Related