为文字控件创建动态文本

发布于 2024-09-02 21:57:36 字数 1422 浏览 6 评论 0原文

在列表视图事件的 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');"

那么这里发生了什么?我缺少什么?

更新1: 这是浏览器的来源

 <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);"

On the ListView1_ItemDataBound of a list view event, i create the literal.text like so...

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

The problem is that the text is not rendered as it should. On mousing over the literal control the url is

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

So what is going on here? What am i missing?

UPDATE1:
Here is the source from the browser

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

UPDATE2:
And here is the output from the screen

This is the answer  Show me the answer

where...

Show me the answer is the hyperlink to http://localhost:1391/"javascript:void(0);"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千仐 2024-09-09 21:57:36

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

更新:(以下评论)

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

更新2:(以下更新回答)

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

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

我尝试在本地使用带引号的字符串,没有任何问题。您确定在设置文本属性之前没有进行 HTML 编码,或者它不是经过编码的吗?在设置文本属性之前尝试 HTML 解码。

You are missing a space between the end of the href attribute and the onMouseOver attribute.

Update: (following comment)

When hovering over a link, some browsers will show you where the href attribute points. In this case this would be "javascript:void(0);". Some will append the host URL to this preview, some will not.

Update 2: (following update to answer)

Looks like the framework is HTML Encoding the strings you are using. Make sure you set the Mode property of the literal control to LiteralMode.PassThrough.

Update 3: (following some testing)

I tried locally using string with quotes and had no problem. Are you sure you are not HTML encoding before setting the text property, or that it isn't coming in encoded? Try HTML decoding before setting the text property.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文