title: UserControl inside DataList
body: <p>I have a UserControl inside DataList, I fill the controls inside the usercontrol according to the PrimeryKey of the DataList's data. At first load program behaves as expected but when user changes page index all the MessageID's returns 0, most probably value coming with 
   &lt;%# Eval("id").toString()%> is lost. I dont want to hard code the usercontrol because i used it in many place in the project, it makes the code maintainable. How can i correct this behaviour? Thanks in advance.</p>
  
  <p>My code is below:</p>
  
  <pre><code>        &lt;asp:DataList ID="DataList1" runat="server" Width="658px"&gt;
              &lt;ItemTemplate&gt;
                  &lt;table style="width: 100%;"&gt;
                      &lt;tr&gt;
                          &lt;td style="font-weight: 700; color: #FF0000; font-size: medium; font-size: 10pt; font-family: Tahoma"&gt;
                              &lt;%# Eval("hadding") +" ["+Eval("startTime")+" - "+Eval("endTime")+"]"%&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td style="font-weight: 700; font-size: 10pt; font-family: Tahoma"&gt;
                              &lt;%# Eval("location") %&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;                        
                      &lt;tr&gt;
                          &lt;td&gt;
                              &lt;uc1:MyUserControl ID="MyUserControl1" runat="server" MessageID='&lt;%# Eval("id").toString()%&gt;' /&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/table&gt;
  
              &lt;/ItemTemplate&gt;
          &lt;/asp:DataList&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;asp:Button ID="btnfirst" runat="server" Font-Bold="true" Text="&lt;&lt;" Height="31px"
                          Width="43px" OnClick="btnfirst_Click" /&gt;&lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:Button ID="btnprevious" runat="server" Font-Bold="true" Text="&lt;" Height="31px"
                          Width="43px" OnClick="btnprevious_Click" /&gt;&lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:Button ID="btnnext" runat="server" Font-Bold="true" Text="&gt;" Height="31px"
                          Width="43px" OnClick="btnnext_Click" /&gt;&lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:Button ID="btnlast" runat="server" Font-Bold="true" Text="&gt;&gt;" Height="31px"
                          Width="43px" OnClick="btnlast_Click" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
  </code></pre>
  
  <p>and my user control:</p>
  
  <pre><code>Partial Class MyUserControl
    Inherits System.Web.UI.UserControl
  
    Private _messageID As Integer
  
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      If (_messageID &gt; 0) Then
          Fill(_messageID)
      End If
    End Sub
  
  
    Public Property MessageID As Integer
      Get
          Return _messageID
      End Get
      Set(value As Integer)
          _messageID = value
      End Set
    End Property
  
    Protected Sub Fill(messageID As Integer)
      'Some code
    End Sub
  
  End Class
  </code></pre>