Server Tags with HTML and Code Blocks inside

213 Views Asked by At

I'm trying to do something like this:

<asp:ListItem><div><%= Message.Success %></div></asp:ListItem>

but it gives me this error:

ASP.NET runtime error: Code blocks are not supported in this context.

Any ideas as to how to work around this error?

1

There are 1 best solutions below

4
VDWWD On BEST ANSWER

You need a Binding Expression inside Controls <%# %>.

<asp:ListView ID="ListView1" runat="server">
    <ItemTemplate>
        <div>
            <%# Message.Success %>
        </div>
    </ItemTemplate>
</asp:ListView>

However this does not work in a ListItem. You will need to add that item with code if you want the Message.Success to be displayed.

DropDownList1.Items.Add(new ListItem() { Text = Message.Success, Value = "0" });