Escaping ASP.NET tags

When you generate ASP.NET markup with CodeSmith Generator, the <% tags you want in the output would otherwise be read by Generator as template code. To write a literal <%, escape the opening tag as <%%. Generator writes <% to the output and doesn't treat it as the start of a code block.

Only the opening tag needs escaping; leave the closing %> as it is.

Example

Say you want to generate this FormView markup, which contains a data-binding expression:

<asp:FormView ID="FormView1" DataSourceID="SqlDataSource1" DataKeyNames="ProductID" RunAt="server">
  <ItemTemplate>
    <table>
      <tr>
        <td align="right"><b>Product ID:</b></td>
        <td><%# Eval("ProductID") %></td>
      </tr>
    </table>
  </ItemTemplate>
</asp:FormView>

In the template, escape the <%# Eval("ProductID") %> expression like this:

<asp:FormView ID="FormView1" DataSourceID="SqlDataSource1" DataKeyNames="ProductID" RunAt="server">
  <ItemTemplate>
    <table>
      <tr>
        <td align="right"><b>Product ID:</b></td>
        <td><%%# Eval("ProductID") %></td>
      </tr>
    </table>
  </ItemTemplate>
</asp:FormView>