ASP.NET - Proper way to initialize a user control created in a repeater?
<p>Relevant code from DetailsBERS.ascx file:</p>

<pre><code>&lt;%@ Register Src="BERS.ascx" TagName="BERS" TagPrefix="ucBERS" %&gt;


&lt;asp:Repeater ID="repeatBERS" runat="server"&gt;&lt;ItemTemplate&gt;
 &lt;tr&gt;
 &lt;td id="Td1" runat="server"&gt;
  &lt;asp:TextBox runat="server" ID="txtTest" Text='&lt;%#DataBinder.Eval(Container, "DataItem.id_bers")%&gt;' MaxLength='&lt;%#DataBinder.Eval(Container, "DataItem.id_bers")%&gt;' /&gt;
  &lt;ucBERS:BERS ID="ucBERS" runat="server" IdBers='&lt;%#DataBinder.Eval(Container, "DataItem.id_bers")%&gt;' /&gt;
 &lt;/td&gt;
 &lt;/tr&gt;
&lt;/ItemTemplate&gt;&lt;/asp:Repeater&gt;
</code></pre>

<p>Relevant code from DetailsBERS.ascx.cs file:</p>

<pre><code> protected void ddlPartie_SelectedIndexChanged(object sender, EventArgs e)
 {
  IdPartieStage = Convert.ToInt32(ddlPartie.SelectedValue);
  DisplayBers();
  upDetailsBERS.Update();
 }

 private void DisplayBers()
 {
  using (SqlCommand cmd = new SqlCommand(Resources.Select.GetBersList,
   new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString)))
  {
   try
   {
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@idPartieStage", IdPartieStage);
    cmd.Connection.Open();
    SqlDataReader read = cmd.ExecuteReader();

    repeatBERS.DataSource = read;
    repeatBERS.DataBind();
   }
   catch (Exception ex)
   {
    throw new Exception("Could not DisplayBers().", ex);
   }
   finally
   {
    if (cmd != null)
     cmd.Connection.Close();
   }
  }
 }
</code></pre>

<p>Relevant code from BERS.ascx.cs file:</p>

<pre><code>protected override void OnPreRender(EventArgs e)
 {
  base.OnPreRender(e);

  PopulateControls();
  PopulateBasicBersInfo();
 }

 private int _idBers;
 public int IdBers
 {
  //set { _idBers = value; }
  set { txtTest.Text = value.ToString(); }
  //get { return _idBers; }
  get { return Convert.ToInt32(txtTest.Text); }
 }
</code></pre>

<p>OK, now my question/problem stems with my weak grasp of ASP.net and how to work with its creative way of initializing and creating controls.</p>

<p>If I use the above it works, in the beginning, until I do a postback (from button click) and try to get at IdBers again - txtTest.Text == "" and I get an exception. (Same result if I use the private int _idBers as the basis for IdBers.)</p>

<p>I believe the problem lies with the fact that my IdBers gets assigned late in the game and so isn't saved in the viewstate...</p>

<p>How am I supposed to create/initialize my BERS control if not by assigning to its IdBers property in the DetailsBERS.ascx file (IdBers='&lt;%#DataBinder.Eval(Container, "DataItem.id_bers")%>')? (I have since implemented Viewstate as suggested by jdt199, so this part is resolved - thanks jdt199.)</p>

<p>More importantly, I need this value within my OnInit stage so I can present the correct data within the control - is this possible? (Question suggested in my title but which I forgot to include into the post's main text.)</p>
