title: How to access textbox, label inside update panel from code behind using asp.net web forms
body: <p>I have a few controls defined inside an update panel which are bound to repeater control. I need to hide and show the user name and country based on anonymous fields, but the problem is that I'm not able to access the controls defined inside update panel programmatically.</p>
  
  <p>How can I access these controls, I looked on the net also but couldn't find many references  </p>
  
  <p>Below is the code from aspx page and .cs page</p>
  
  <pre><code>&lt;asp:UpdatePanel ID="updPnlComments" runat="server"&gt;
  &lt;ContentTemplate&gt;
  &lt;table border="0" width="100%" &gt;&lt;tr&gt;&lt;td valign="top"&gt;
      &lt;asp:Repeater ID="rptCommentList" runat="server" EnableViewState="false"&gt;
         &lt;ItemTemplate&gt;
              &lt;div id="divComPostDate" class="ArticlePubDate"&gt;
                  &lt;asp:Label ID="lblComDateAdded" runat="server" Text="Added"&gt;&lt;/asp:Label&gt; 
                  &lt;asp:Label ID="lblComPostDate" runat="server" Text='&lt;%# FormatCommentDate(Eval("comPostDate")) %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/div&gt;
              &lt;div id="divComMSGDetail" class="PostCommentMSG"&gt;
                  &lt;asp:Label ID="lblComMSGDetails"  runat="server" Text='&lt;%# Eval("comMessage") %&gt;'&gt;&lt;/asp:Label&gt; 
              &lt;/div&gt;
              &lt;div id="divComUserName" class="ComUserName"&gt;
                  &lt;asp:Label ID="lblComUserName" runat="server" Text='&lt;%# Eval("comFullName") %&gt;'&gt;&lt;/asp:Label&gt;,
                  &lt;asp:Label ID="lblComCountry" runat="server" Text='&lt;%# Eval("comCountry") %&gt;'&gt;&lt;/asp:Label&gt;
                  &lt;asp:Label ID="lblUserAnonymous" runat="server" Text='&lt;%# showUserName(Eval("comAnonymous")) %&gt;' Visible=false&gt;&lt;/asp:Label&gt;
              &lt;/div&gt;
              &lt;div id="divThinlLine" class="ThinLine" &gt;&lt;/div&gt;
          &lt;/ItemTemplate&gt;
       &lt;/asp:Repeater&gt;
    &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;
      &lt;table border="0" width="90%" &gt;&lt;tr&gt;&lt;td align="center" valign="bottom" height="50px"&gt;
        &lt;table border="0"&gt;&lt;tr&gt;&lt;td align="center" &gt;
               &lt;uc1:PagerControl ID="PagerControl1" runat="server"  CssClass="gold-pager"  PageMode="LinkButton"  /&gt;
        &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
      &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
  &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
  &lt;/ContentTemplate&gt;
  &lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <p><strong>Code Behind</strong></p>
  
  <pre><code>protected string FormatCommentDate(object dt)
  {
      string date;
      date  = String.Format("{0:hh:mm, MMMM dd, yyyy}", dt);
      return date;
  }
  
  protected string showUserName(object userName)
  {
      String str=null;
      try
      {
          Boolean isUserAnonymous = Convert.ToBoolean(userName);
  
          if (isUserAnonymous == true)
          {
              // Not able to access lblComUserName CONTROL here
  
          }
  
      }
      catch (Exception ex)
      {
  
      }
  
      return str;
  
  }
  </code></pre>
  
  <p><strong>Function To bind repeater control with Pager and Repeater control</strong></p>
  
  <pre><code>protected void getCommentsList(int iArticleID)
  {
      try
      {
  
          PagerControl1.PageSize = 4;
          //PagerControl1.TotalItems = 1;
          //PagerControl1.PageMode = 4;
          PagerControl1.DisplayEntriesCount = 5;
          //Will show 2 links after ...
          PagerControl1.EdgeEntriesCount = 0;
          DataSet ds = DataProvider.GetCommentList(iArticleID);
          DataView dv = ds.Tables[0].DefaultView;
  
          //pass the datatable and control to bind
          PagerControl1.BindDataWithPaging(rptCommentList, dv.Table);
  
      }
      catch (Exception ex)
      {
          HttpContext.Current.Response.Redirect("Message.aspx?msg=Invalid Request");
      }
  </code></pre>