title: Set UserControl Property value From ASP.NET markup
body: <p>I need to set a property value of a user control from the markup.</p>
  
  <p>I need to set the property called "ItemIndex" in my user control from the markup.</p>
  
  <p>for some unfortunate reason, "&lt;%: x %>" part of ItemIndex="&lt;%: x %>" doesn't get resolved.</p>
  
  <p>Basically the value of ItemIndex becomes "&lt;%: x %>" rather than becoming the actual value of x.</p>
  
  <p>Below is the code (please note the comments in CAPS).</p>
  
  <pre><code>&lt;%@ Register TagPrefix="DDLControls" TagName="MainMenuItem" Src="~/Views/Header/MainMenuItemControl.ascx" %&gt;
  &lt;div id="MainMenu"&gt;
      &lt;table cellpadding="0" cellspacing="0" border="0"&gt;
      &lt;tr&gt;
          &lt;%   
              foreach (MenuItem mi in Model.Items)
              {
                  string x = Model.Items.IndexOf(mi).ToString();
          %&gt;
          &lt;td&gt;
              &lt;%= x %&gt;  &lt;&lt;-- THIS GETS RESOLVED TO 0,1,2,3,4,...
              &lt;DDLControls:MainMenuItem ItemIndex="&lt;% x %&gt;" runat="server" /&gt;  &lt;&lt;-- THIS DOESN'T GET RESOLVED
          &lt;/td&gt;
          &lt;%
  
              } 
          %&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>