tags:

views:

246

answers:

3

I am trying to do something like this:

<asp:Button ID="btnSearch" 
            runat="server" 
            CssClass="greybtn" 
            Text='<span>Search</span>'
            OnClick="btnSearch_Click" />

It displays <span>Search</span> instead of just Search.

+1  A: 

You can't put markup inside a button. An asp:Button control just renders as an input button HTML tag: <input type="button" value="<span>Search</span>" /> (technically value="&lt;span&gt;Search&lt;/span&gt;" />). The browser treats the contents of the value attribute as a literal string.

However, you can put markup inside a <button><span>Search</span></button> (you can put quite a bit of HTML in there, including images). This question talks about building a control which emits the button tag.

Rex M
A: 

No. It renders a tag, so whatever you put in the Text property gets rendered as that button's value.

Pawel Krakowiak
A: 

The text property will automatically turn < and > into the entities &lt; and &gt;. More than that, button renders to html as an input element, with the text set in it's value property.

Do you maybe want a HyperLink or Label control instead?

Joel Coehoorn