Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7401815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:34:32+00:00 2026-05-29T04:34:32+00:00

I have a few controls defined inside an update panel which are bound to

  • 0

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.

How can I access these controls, I looked on the net also but couldn’t find many references

Below is the code from aspx page and .cs page

<asp:UpdatePanel ID="updPnlComments" runat="server">
<ContentTemplate>
<table border="0" width="100%" ><tr><td valign="top">
    <asp:Repeater ID="rptCommentList" runat="server" EnableViewState="false">
       <ItemTemplate>
            <div id="divComPostDate" class="ArticlePubDate">
                <asp:Label ID="lblComDateAdded" runat="server" Text="Added"></asp:Label> 
                <asp:Label ID="lblComPostDate" runat="server" Text='<%# FormatCommentDate(Eval("comPostDate")) %>'></asp:Label>
            </div>
            <div id="divComMSGDetail" class="PostCommentMSG">
                <asp:Label ID="lblComMSGDetails"  runat="server" Text='<%# Eval("comMessage") %>'></asp:Label> 
            </div>
            <div id="divComUserName" class="ComUserName">
                <asp:Label ID="lblComUserName" runat="server" Text='<%# Eval("comFullName") %>'></asp:Label>,
                <asp:Label ID="lblComCountry" runat="server" Text='<%# Eval("comCountry") %>'></asp:Label>
                <asp:Label ID="lblUserAnonymous" runat="server" Text='<%# showUserName(Eval("comAnonymous")) %>' Visible=false></asp:Label>
            </div>
            <div id="divThinlLine" class="ThinLine" ></div>
        </ItemTemplate>
     </asp:Repeater>
  </td></tr><tr><td>
    <table border="0" width="90%" ><tr><td align="center" valign="bottom" height="50px">
      <table border="0"><tr><td align="center" >
             <uc1:PagerControl ID="PagerControl1" runat="server"  CssClass="gold-pager"  PageMode="LinkButton"  />
      </td></tr></table>
    </td></tr></table>
</td></tr></table>
</ContentTemplate>
</asp:UpdatePanel>

Code Behind

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;

}

Function To bind repeater control with Pager and Repeater control

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");
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:34:33+00:00Added an answer on May 29, 2026 at 4:34 am

    The problem isn’t with UpdatePanel, but with the Repeater. Controls inside the update panel can be directly accessed within the scope of the page (such as the repeater itself), whilst controls within the repeater have to be “found” during or after they have been bound. Your code within the repeater is a template for many items and not specific to any one.

    I’d suggest adding an ItemDataBound event to your repeater and perform the logic inside this event as each item is being bound to the repeater.

    <asp:Repeater ID="rptCommentList" runat="server" EnableViewState="false"
         OnItemDataBound="rptCommentList_ItemDataBound">
    

     

    protected void rptCommentList_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 
        {
            // get the data item
            MyObject myObject = (MyObject)e.Item.DataItem;
    
            // find the label
            Label lblComUserName = (Label)e.Item.FindControl("lblComUserName");
    
            // do the magic!
            if (myObject.comAnonymous)
                 lblComUserName.Visible = false;
        }
    }
    

    Obviously, replace MyObject with the object type of the collection/list/table you are binding to the repeater in the first place.

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few user controls that need to be shared between multiple Silverlight
I have a few DependencyProperties defined in some custom user controls. I'd like for
I have a user control that has a few public properties, one is an
I have a few before filters which I am using to control access to
I have few controls on my MainForm in Winforms application. For example control that
I have a few controls designed to verify certain data before a user may
I have few jquery tabs on a usercontrol that loads a separate user control
I have a few controls that inherit from ASP.NET buttons and use onserverclick .
I have a few listview controls on a windows form and i've assigned a
I have a few asp:textbox controls in a form on a webpage, below is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.