title: How to provide 'data' to User Control inside repeater?
body: <p>Can somebody explain the easiest way to provide data to a <strong>user</strong> control inside a repeater?</p>
  
  <p>I have the following:</p>
  
  <h1>Default.aspx</h1>
  
  <pre><code>&lt;!-- this.GetData() returns IEnumerable&lt;Object&gt; --&gt;
  &lt;asp:Repeater runat="server" datasource='&lt;%#this.GetData()%&gt;'&gt;
      &lt;ItemTemplate&gt;
          &lt;my:CustomControl runat="server" datasource='&lt;%#Container.DataItem %&gt;
      &lt;/ItemTemplate&gt;
  &lt;/asp:Repeater&gt;
  </code></pre>
  
  <p><strong>Codebehind</strong></p>
  
  <pre><code>    protected void Page_Load(object sender, EventArgs e)
      {
          this.DataBind();
      }
  </code></pre>
  
  <h1>CustomControl.ascx</h1>
  
  <pre><code>&lt;!-- Object has property Title --&gt;
  &lt;h1&gt;&lt;%#this.DataSource.Title%&gt;&lt;/h1&gt;
  </code></pre>
  
  <p><strong>Codebehind:</strong></p>
  
  <pre><code>[System.ComponentModel.DefaultBindingProperty("DataSource")]
  public partial class CustomControl : System.Web.UI.UserControl
  {
      public Item DataSource { get; set; }
  
      protected void Page_Load(object sender, EventArgs e)
      {
          var x = this.DataSource; //null here
      }
  
      protected void Page_PreRender(object sender, EventArgs e)
      {
          var x = this.DataSource; //still null
      }
  }
  </code></pre>