I have a repeater control where the <%#DataBinder.Eval(Container.DataItem, "Display")%> part doesn't show up. The code that the "Display" stores is set as follows:
我有一个转发器控件,其中<%#DataBinder.Eval(Container.DataItem,“Display”)%>部分没有出现。 “Display”存储的代码设置如下:
item.Display = "<script type='text/javascript'>AudioPlayer.embed('ffcedea7-
4822-465f-85b6-89924f7b81fa', {soundFile: 'http://s3.amazonaws.com/blah/af8g7fd3-1793
-4b5e-92b7-9d11ad1cc19c.mp3'});</script>";
After the page load, the audio embed file doesn't show up. The code doesn't even show up in the source. If I add a random string after the ending script tag, that random string will show up.
页面加载后,音频嵌入文件不会显示。代码甚至没有显示在源代码中。如果我在结束脚本标记之后添加随机字符串,则会显示该随机字符串。
item.Display = "<script type='text/javascript'>AudioPlayer.embed('ffcedea7-4822-4
65f-85b6-89924f7b81fa', {soundFile: 'http://s3.amazonaws.com/blah/af8g7fd3-1793-4b
5e-92b7-9d11ad1cc19c.mp3'});</script> THIS IS THE RANDOM STRING";
So, on the page source it will have " THIS IS THE RANDOM STRING" but not the script part.
因此,在页面源上它将具有“这是随机字符串”而不是脚本部分。
Does anyone know what is causing this issue and how it can be fixed? Thanks!
有谁知道导致这个问题的原因以及如何解决这个问题?谢谢!
Edit: Here is the repeater code:
编辑:这是转发器代码:
<asp:Repeater ID="repeaterAddable" runat="server">
<ItemTemplate>
<div class="background-white">
<div style="padding: 15px;">
<table style="width: 100%" cellspacing="5">
<tr>
<td colspan="3" align="right">
Include this? <input type="checkbox" name="include<%#DataBinder.Eval(Container.DataItem, "Index")%>" />
</td>
</tr>
<tr>
<td style="width: 30%;" valign="top">
</td>
<td style="width: 30%;" valign="top">
<div class="media">
<%#DataBinder.Eval(Container.DataItem, "Display")%>
</div>
</td>
<td style="width: 30%;" valign="top">
</td>
</tr>
</table>
</div>
</div>
<br />
</ItemTemplate>
</asp:Repeater>
2 个解决方案
#1
Try adding a Literal control instead, and bind its text property to the desired content. E.g:
尝试添加Literal控件,并将其text属性绑定到所需的内容。例如:
<div class="media">
<asp:Literal runat="server" Text='<%# Eval("Display") %>' />
</div>
#2
Maybe you have some safe settings on your page or webconfig...
也许你的页面或webconfig上有一些安全设置......
I tried to reproduce your situation in a brand new page, but it actually worked.
我试图在一个全新的页面中重现你的情况,但它确实有效。
public class A
{
public string Display { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
var list = new List<A>();
var a = new A();
a.Display = "<script>alert('hi')</script>S<br/>";
list.Add(a);
rep.DataSource = list;
rep.DataBind();
}
And in the page
并在页面中
<asp:Repeater ID="rep" runat="server">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Display") %>
</ItemTemplate>
</asp:Repeater>
Perhaps you can try to set the Display
with HttpUtility.UrlEncode
and get it with HttpUtility.UrlDecode
...
也许您可以尝试使用HttpUtility.UrlEncode设置Display并使用HttpUtility.UrlDecode获取它...
#1
Try adding a Literal control instead, and bind its text property to the desired content. E.g:
尝试添加Literal控件,并将其text属性绑定到所需的内容。例如:
<div class="media">
<asp:Literal runat="server" Text='<%# Eval("Display") %>' />
</div>
#2
Maybe you have some safe settings on your page or webconfig...
也许你的页面或webconfig上有一些安全设置......
I tried to reproduce your situation in a brand new page, but it actually worked.
我试图在一个全新的页面中重现你的情况,但它确实有效。
public class A
{
public string Display { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
var list = new List<A>();
var a = new A();
a.Display = "<script>alert('hi')</script>S<br/>";
list.Add(a);
rep.DataSource = list;
rep.DataBind();
}
And in the page
并在页面中
<asp:Repeater ID="rep" runat="server">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Display") %>
</ItemTemplate>
</asp:Repeater>
Perhaps you can try to set the Display
with HttpUtility.UrlEncode
and get it with HttpUtility.UrlDecode
...
也许您可以尝试使用HttpUtility.UrlEncode设置Display并使用HttpUtility.UrlDecode获取它...