How to access a text field, mark the internal update panel using code using asp.net web forms

I have several controls defined inside the update panel that are tied to repeater control. I need to hide and show the username and country based on anonymous fields, but the problem is that I cannot programmatically access the controls defined inside the update panel.

How can I access these controls, I also looked at the network, but could not find many links

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 for

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 associate 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");
    }
+5
source share
2

UpdatePanel, Repeater. (, ), "" , . .

ItemDataBound , .

<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;
    }
}

, MyObject //, .

, .

+4

 Label lbl=(Label)Repeater1.FindControl("lbl1");

. .

+4

All Articles