Search code examples
c#asp.netinline-code

C# code in ASP.NET control property


I would like to write some code in an asp.net Button Text property. Is this possible?

This is how I tried it, but this doesn't work

<% 
    foreach (Reference reference in allReferences)
    {
%>
        <asp:Button Text="<%= reference.Title %>" ID="myButton" runat="server" />
<%
    }           
%>

When this is rendered, it shows literally the string "<%= reference.Title %>".

Is there another syntax, or something else?

Thanks, Vincent


Solution

  • you need to use '<%= reference.Title %>' , so use a single quote instead of double