2

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:

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-465f-85b6-89924f7b81fa',
    {soundFile: 'http://s3.amazonaws.com/blah/af8g7fd3-1793-4b5e-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>
4

2 回答 2

0

尝试添加一个 Literal 控件,并将其文本属性绑定到所需的内容。例如:

<div class="media">
  <asp:Literal runat="server" Text='<%# Eval("Display") %>' />
</div>
于 2009-01-18T21:59:56.757 回答
0

也许您的页面或 webconfig 上有一些安全设置...

我试图在一个全新的页面中重现您的情况,但它确实有效。

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();
}

并且在页面中

<asp:Repeater ID="rep" runat="server">
    <ItemTemplate>
        <%# DataBinder.Eval(Container.DataItem, "Display") %>
    </ItemTemplate>
</asp:Repeater>

也许您可以尝试设置DisplayHttpUtility.UrlEncode使用HttpUtility.UrlDecode...

于 2010-07-22T01:34:27.653 回答