为文字控件创建动态文本

时间:2010-05-26 17:10:05

标签: asp.net html dynamic literals

在列表视图事件的ListView1_ItemDataBound上,我创建了literal.text,就像这样......

<span style=&quot;position:relative;&quot;>
style="position:relative">
<span id=&quot;term1&quot; class=&quot;popup&quot;>This id="term1" class="popup">This is the answer!</span>
<a href=&quot;javascript:void(0);&quot;onMouseover=&quot;ShowPop('term1');&quot; onMouseout=&quot;HidePop('term1');&quot;>Show href="javascript:void(0);"onMouseover="ShowPop('term1')" onMouseout="HidePop('term1')">Show me the answer</a></span>

问题是文本没有按原样呈现。 鼠标悬停文字控件

http://localhost:1391/"javascript:void(0);"onMouseover="ShowPop('term1');"

那么这里发生了什么?我错过了什么?

UPDATE1: 这是浏览器的来源

 <span style=&quot;position:relative;&quot;> <span id=&quot;term1&quot; class=&quot;popup&quot;>This is the answer!</span> <a href=&quot;javascript:void(0);&quot; onMouseover=&quot;ShowPop('term1');&quot; onMouseout=&quot;HidePop('term1');&quot;>Show me the answer</a></span>

UPDATE2: 这是屏幕的输出

This is the answer  Show me the answer

其中...

向我显示答案是指向http://localhost:1391/"javascript:void(0);"

的超链接

1 个答案:

答案 0 :(得分:1)

您在href属性的末尾和onMouseOver属性之间缺少空格。

更新:(以下评论)

将鼠标悬停在某个链接上时,某些浏览器会显示href属性指向的位置。在这种情况下,这将是“javascript:void(0);”。有些会将主机URL附加到此预览中,有些则不会。

更新2:(更新后回答)

看起来框架是HTML编码您正在使用的字符串。确保将文字控件的Mode属性设置为LiteralMode.PassThrough

更新3:(经过一些测试)

我在本地尝试使用带引号的字符串并没有问题。在设置text属性之前,您确定自己不是HTML编码,或者它是否未进行编码?在设置text属性之前尝试HTML解码。