简体   繁体   English

无法使用iframe代码设置文本框

[英]Textbox cannot be set with iframe tags

I am trying to display a textbox on UI where the value of the textbox is initialized to the following. 我试图在UI上显示一个文本框,其中该文本框的值初始化为以下值。

Here is my code. 这是我的代码。

...
<asp:TextBox ID="txtTest" runat="server" Visible="true" />
...
protected void Page_Load(object sender, EventArgs e)
{
    txtTest.Text = "<iframe width=\"100%\" height=\"300\" src=\"//jsfiddle.net/vhyseni/rj0tv76x/embedded/\" allowfullscreen=\"allowfullscreen\" frameborder=\"0\"></iframe>"
}

However the textbox is empty on page load. 但是,文本框在页面加载时为空。 If I misspell iframe or use some other text (even eg "hello") the textbox is initialized correctly. 如果我拼错iframe或使用其他一些文本(甚至是“ hello”),则文本框将正确初始化。 Is there some issue with asp textbox that makes this string invalid? asp文本框是否存在使该字符串无效的问题?

您必须先对HTML进行编码,然后再将其分配给txtTest.Text

txtTest.Text = Server.HtmlEncode("you html");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM