title: ASP.NET inline code in a server control
body: <p>Ok, we had a problem come up today at work. It is a strange one that I never would have even thought to try.</p>
  
  <pre><code>&lt;form id="form1" runat="server" method="post" action="Default.aspx?id=&lt;%= ID %&gt;" &gt;
  </code></pre>
  
  <p>Ok, it is very ugly and I wouldn't have ever tried it myself. It came up in some code that was written years ago but had been working up until this weekend after a bunch of updates were installed on a client's web server where the code is hosted.</p>
  
  <p>The actual result of this is the following html:</p>
  
  <pre><code>&lt;form name="form1" method="post" action="Default.aspx?id=&amp;lt;%= ID %&gt;" id="form1"&gt;
  </code></pre>
  
  <p>The url ends up like this:</p>
  
  <pre><code>http://localhost:6735/Default.aspx?id=&lt;%= ID %&gt;
  </code></pre>
  
  <p>Which as you can see, demonstrates that the "&lt;" symbol is being encoded before ASP.NET actually processes the page. It seems strange to me as I thought that even though it is not pretty by any means, it should work. I'm confused.</p>
  
  <p>To make matters worse, the client insists that it is a bug in IE since it appears to work in Firefox. In fact, it is broken in Firefox as well, except for some reason Firefox treats it as a 0.</p>
  
  <p>Any ideas on why this happens and how to fix it easily? Everything I try to render within the server control ends up getting escaped.</p>
  
  <p><strong>Edit</strong>
  Ok, I found a "fix"</p>
  
  <pre><code>&lt;form id="form1" runat="server" method="post" action='&lt;%# String.Format("Default.aspx?id={0}", 5) %&gt;' &gt;
  </code></pre>
  
  <p>But that requires me to call DataBind which is adding more of a hack to the original hack. Guess if nobody thinks of anything else I'll have to go with that.</p>