title: how to retrieve TextBox control's ClientID within the ListView's ItemDataBound event?
body: <p>I am having trouble retrieving a TextBox control's ClientID value from a ListView control.
  I thought this syntax would return me the ClientID fine(very strange):
  <strong>((TextBox)e.Item.FindControl(&quot;amount&quot;)).ClientID;</strong></p>
  <p>but it keeps throwing this exception:</p>
  <p><strong>&quot;Index was out of range. Must be non-negative and less than the size of the collection.
  Parameter name: index&quot;</strong></p>
  <p>Any help is greatly appreciated.
  Below is my code:
  aspx:</p>
  <pre><code>&lt;asp:ListView ID=&quot;categories&quot; runat=&quot;server&quot; 
      ClientIDRowSuffix=&quot;ID&quot;
       ItemPlaceholderID=&quot;categoryItem&quot;
       DataKeyNames=&quot;ID&quot; onitemdatabound=&quot;categories_ItemDataBound&quot;&gt;
      &lt;ItemTemplate&gt;             
              &lt;div class=&quot;category&quot;&gt;
                  &lt;asp:TextBox ID=&quot;amount&quot; runat=&quot;server&quot; /&gt;                   
              &lt;/div&gt;
       &lt;/ItemTemplate&gt;
  
  &lt;/asp:ListView&gt;
  </code></pre>
  <p>codebehind:</p>
  <pre><code>public string AmountTextBoxClientID { get; set; }
  
      protected string GetAmountTextBoxClientID()
       {
           return this.AmountTextBoxClientID;
       }
  
  
  protected void categories_ItemDataBound(object sender, ListViewItemEventArgs e)
       {
           switch (e.Item.ItemType)
           {
               case ListViewItemType.DataItem:
                   
                  TextBox amountTextBox = (TextBox)e.Item.FindControl(&quot;amount&quot;);//this line excutes without any error
                   amountTextBox.Text = categoryAmount.ToString(&quot;C&quot;);
                   amountTextBox.Attributes.Add(&quot;readonly&quot;, &quot;readonly&quot;);
                  
                  this.AmountTextBoxClientID = amountTextBox.ClientID; //this line keeps throwing the OutOfRange exception
                   break;
           }
        
      }
  </code></pre>