title: ASP.NET: Accessing a WebControl from EditItemTemplate in DataList
body: <p>I am trying to access a webcontrol (a Textbox) from the EditItemTemplate of a DataList, so I can change it. When I try to do DataList.FindControl("TextboxID") it comes back with null because it doesn't recognize the textbox has rendered.  I've tried looking in the DataBinding, DataBound events and those don't work either.</p>
  
  <p>To be more specific, I need to change the value of a textbox when the user uses a Calendar control, so I need to access the control from EditItemTemplate in the Calendar_SelectionChanged event.</p>
  
  <p>Anyone have any ideas or workarounds?  Thanks!</p>
  
  <p>Code:</p>
  
  <pre><code>protected void calendar1_SelectionChanged(object sender, EventArgs e)
  {
      // Access EditItemTemplate Control
  }
  
  
  &lt;asp:DataList ID="DataListMaintenance" runat="server" 
                                          oncancelcommand="DataListMaintenance_CancelCommand" 
                                          oneditcommand="DataListMaintenance_EditCommand" 
                                          onupdatecommand="DataListMaintenance_UpdateCommand" 
                                          DataSourceID = "LMMaintDataSource" 
                                          ondeletecommand="DataListMaintenance_DeleteCommand"&gt;
                                      &lt;EditItemTemplate&gt;
                                          &lt;table width = "100%" cellpadding = "2" cellspacing = "1"&gt;
                                              &lt;tr&gt;
                                                  &lt;td valign = "top"&gt;
                                                      &lt;b&gt;Contract Start Date:&lt;/b&gt;
                                                  &lt;/td&gt;
                                                  &lt;td&gt;
                                                      &lt;asp:TextBox ID="txtContractStart" runat="server" Text = '&lt;%# Bind("ContractStartDate") %&gt;'&gt;&lt;/asp:TextBox&gt;
                                                      &lt;% if (!calDateEdit.Visible)
                                                         { %&gt;
                                                      &lt;asp:LinkButton ID="linkChoose" runat="server" onclick="linkChoose2_Click"&gt;Choose&lt;/asp:LinkButton&gt;
                                                      &lt;%} %&gt;
                                                      &lt;% if (calDateEdit.Visible)
                                                         { %&gt;
                                                      &lt;asp:LinkButton ID="linkCancel" runat="server" onclick="linkCancel2_Click"&gt;Cancel&lt;/asp:LinkButton&gt;
                                                      &lt;%} %&gt;
                                                  &lt;/td&gt;
                                                  &lt;td&gt;
                                                      &lt;asp:Calendar ID="calDateEdit" runat="server" Visible ="false" 
                                      onselectionchanged="calendar1_SelectionChanged"&gt;
                                       &lt;SelectedDayStyle BorderColor="Blue" BorderStyle="Solid" /&gt;
                                   &lt;/asp:Calendar&gt;
                                                  &lt;/td&gt;
                                              &lt;/tr&gt;
                                              &lt;tr&gt;
                                                  &lt;td&gt;
                                                      &lt;asp:Button ID="cmdUpdate" runat="server" Text="Update" CommandName = "Update" /&gt;&amp;nbsp;&lt;asp:Button ID="cmdCancel" runat="server" Text="Cancel" CommandName = "Cancel" /&gt;
                                                  &lt;/td&gt;
                                              &lt;/tr&gt;
                                          &lt;/table&gt;
                                      &lt;/EditItemTemplate&gt;
                                      &lt;ItemTemplate&gt;
                                          &lt;table width = "100%" cellpadding = "2" cellspacing = "1"&gt;
                                              &lt;tr&gt;
                                                  &lt;td valign = "top"&gt;
                                                      &lt;b&gt;Contract Start Date:&lt;/b&gt;
                                                  &lt;/td&gt;
                                                  &lt;td&gt;
                                                      &lt;asp:Label ID="lblStart" runat="server" Text='&lt;%# DataBinder.Eval(Container.DataItem, "ContractStartDate")%&gt;'&gt;&lt;/asp:Label&gt;
                                                  &lt;/td&gt;
                                              &lt;/tr&gt;
                                          &lt;/table&gt;
                                      &lt;/ItemTemplate&gt;
                                      &lt;/asp:DataList&gt;
  </code></pre>