开发者

Stop asp:Button Text from being HTML encoded

I am maintaining an ASP.NET 3.5 application and I'd like to add some "off screen" html content within the Text property of a Button control in order to make it 开发者_运维百科more accessible, e.g.

<asp:Button CssClass="std-text" runat="server" ID="btnChangeLocation"
            OnClick="btnChangeLocation_Click" 
            Text="Set<span class='offscreen'> Location</span>" />

but the Text is always HTML-encoded, how can I stop this?


one way to do that is use a javascript replacement, for example:

<asp:Button CssClass="std-text" runat="server" 
       ID="btnChangeLocation" OnClick="btnChangeLocation_Click" 
       data-text="Set<span class='offscreen'> Location</span>" 
       Text="replace-text" />

and call a replace method on Load like:

$(function() {

    replaceAllTexts();
});

function replaceAllTexts() {

    // for each button
    $("input[type='button']").each(function() {

        // if the text is 'replace-text' and there is a data-text attribute
        if( $(this).text() === "replace-text" && $(this).attr("data-text") ) {
            // replace button's text
            $(this).html( $(this).attr("data-text") );
        }
    });
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜