简体   繁体   中英

Server Tags with HTML and Code Blocks inside

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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