我想在.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);
}
这不能解决我的目的,因为它显示如下:
当它应该在HTML中呈现时,它应该如下所示:
<a href="tel:888.444.4444" class="phone"><span class="icon phone">m </span>888.444.4444</a>
任何人都可以帮我解决这个问题吗?
答案 0 :(得分: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);
答案 1 :(得分: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);
}