如何在后面的代码中防止属性的HTML编码? [英] How do I prevent HTML encoding of attributes in the code behind?
本文介绍了如何在后面的代码中防止属性的HTML编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的aspx中有以下内容。
I have the following in my aspx.
<html>
<body>
<input id="but" type="button" value="ClickMe" />
</body>
</html>
后面的代码
//Pageload
but.Attributes.Add("onclick", "this.parentNode.innerHTML += '<a id=""link"" href=""mylink""></a>';document.getElementById(""link"").click();");
呈现的html
<input name="ctl00$Content$btn" type="button" id="ctl00_Content_btn" value="ClickMe"
onclick="this.parentNode.innerHTML += '<a id="link" href="mylink"></a>';document.getElementById("link").click();" />
如何获取<
>
字符才能正确显示?
How can I get the <
>
"
characters to render properly?
推荐答案
未经编码就无法呈现这些字符。
You cannot render these characters without encoding.
来自 MSDN
您不能使用
Attributes集合将客户端脚本添加到WebControl实例中。要添加客户端脚本,请使用页面控件上的ClientScript
属性。
如果您坚持,只需呈现自己的控件即可。
If you insist, just render your own control.
这篇关于如何在后面的代码中防止属性的HTML编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文