views:

801

answers:

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-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>
A: 

Try adding a Literal control instead, and bind its text property to the desired content. E.g:

<div class="media">
  <asp:Literal runat="server" Text='<%# Eval("Display") %>' />
</div>
M4N
I was thinking that might work too, but haven't got the means to test it
Russ Cam
I just tried that, but the code still didn't show up (even in the source code).
rksprst
A: 

Maybe you have some safe settings on your page or 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...

BrunoLM