title: Variable Not Recognized When Data Binding Attempted
body: <p>Here is a snippet of my code:</p>
  
  <pre><code>&lt;%for (int i = 1; i &lt;= MessageList.Count; i++)
                     {
                         switch (LevelList[i-1])
                         {
                             case 0:%&gt;
                              &lt;div class="well offset1" style="width:80%"&gt;
                                  &lt;h1&gt;&lt;%= MessageList[i - 1].Header%&gt;&lt;/h1&gt;
                                  &lt;p&gt;&lt;%= MessageList[i - 1].Body%&gt;&lt;/p&gt;
                                  &lt;ul&gt;
                                      &lt;li style="display:inline"&gt;Likes: &lt;%= MessageList[i - 1].NumberOfLikes%&gt;&lt;/li&gt;
                                      &lt;li style="display:inline"&gt;Replies: &lt;%= MessageList[i - 1].NumberOfReplies%&gt;&lt;/li&gt;
                                  &lt;/ul&gt;
                                  &lt;ul&gt;
                                      &lt;li style="display:inline"&gt;&lt;asp:Button ID="LikeButton" messID="&lt;%# MessageList[i-1].MessageID %&gt;" runat="server" Text="Like" /&gt;&lt;/li&gt;
                                      &lt;li style="display:inline"&gt;&lt;asp:Button ID="ReplyButton" messID="&lt;%# MessageList[i-1].MessageID %&gt;" runat="server" Text="Reply" /&gt;&lt;/li&gt;
                                  &lt;/ul&gt;
                              &lt;/div&gt;
                              &lt;%break;
  </code></pre>
  
  <p>My problem is with the "messID" in this part:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;li style="display:inline"&gt;&lt;asp:Button ID="LikeButton" messID="&lt;%# MessageList[i-1].MessageID %&gt;" runat="server" Text="Like" /&gt;&lt;/li&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>At first I was attempting to pass a variable to the codebehind using <code>messID="&lt;%= calculated value%&gt;"</code> and using <code>Button.Attribute["messID"]</code> to access this variable, however, instead of passing the calculated variable as a string this passed a string that looked <code>&lt;%= calculated variable%&gt;</code>. After some research I found out that the <code>&lt;%</code> could not be used with asp controls. So now I am attempting to use the <code>&lt;%#</code> tag and <code>DataBind()</code>, however, now whatever is inside the <code>&lt;%#</code> tags is not recognizing the variable <code>i</code> which is part of the <code>forloop</code>. Why does this happen?</p>