0

我想向 .ascx 控件添加一个 HtmlAnchor。到目前为止,我有这样的代码:

private void SetPhoneNumber()
    {
        HtmlAnchor htmlAnchor = new HtmlAnchor();
        const string spanTag = @"<span class=""icon phone"">m</span>";
        string anchor = spanTag + Context.CurrentPhoneNumber();
        htmlAnchor.InnerText = anchor;
        Controls.Add(htmlAnchor);
    }

这并不能解决我的目的,因为它的显示如下:

它需要显示一个电话图标,而不是 span。

当它应该在 HTML 中呈现时,它应该如下所示:

 <a href="tel:888.444.4444" class="phone"><span class="icon phone">m </span>888.444.4444</a>

谁能帮我解决这个问题?

4

2 回答 2

1

设置InnerHtml锚标签:

HtmlAnchor htmlAnchor = new HtmlAnchor();
const string spanTag = @"<span class=""icon phone"">m</span>";
string anchor = spanTag + Context.CurrentPhoneNumber();
htmlAnchor.InnerHtml = anchor;
Controls.Add(htmlAnchor);
于 2013-04-25T20:28:48.603 回答
1

将innertext更改为innerhtml

 private void SetPhoneNumber()
{
    HtmlAnchor htmlAnchor = new HtmlAnchor();
    const string spanTag = @"<span class=""icon phone"">m</span>";
    string anchor = spanTag + Context.CurrentPhoneNumber();
    htmlAnchor.InnerHtml = anchor;
    Controls.Add(htmlAnchor);
}
于 2013-04-25T20:29:08.467 回答