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

  • Home
  • SEARCH
  • 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 6032933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:24:33+00:00 2026-05-23T05:24:33+00:00

I have a repeater that lists customer items, one of which is a button

  • 0

I have a repeater that lists customer items, one of which is a button for more information. When the user clicks that button, a user control appears immediately below it. I’d like for the user control to then close when the button is clicked again. I initially toggled visibility server-side, but I now can’t use this because the user control needs to be loaded on the button click due to parameters that need to bepassed through. I also can’t used show and hide by jquery because that would involve downloading all the data first for the whole page which could make the page too cumbersome.

So currently in each repeater I have a linkbutton with command arguments and an OnCommand event which fires this event:

protected void uxPolicyDocsButton_Command(object sender, CommandEventArgs e)
    {
        //Find Policy Summary control within repeater item in order to toggle visibility

        LinkButton button = sender as LinkButton;
        if (button != null)
        {
            RepeaterItem ri = button.Parent as RepeaterItem;

            if (ri != null)
            {
                PlaceHolder policySummaryPlaceHolder = (PlaceHolder)ri.FindControl("uxPolicySummaryPlaceHolder");                    
                Control policyDocuments = (Control)PolicySummaryPlaceHolder.FindControl("uxPolicyDocumentsControl");


                foreach (Control c in policySummaryPlaceHolder.Controls)
                {
                    //FindControl action goes in here.  Have stepped through though and it doesn't appear
                }

                if (policyDocuments != null)
                {
                    policySummaryPlaceHolder.Controls.Remove(policyDocuments);
                }
                else
                {
                    policyDocuments uxPolicyDocumentsControl = (PolicyDocuments)LoadControl("~/Controls/Home/PolicyDocuments.ascx");
                    uxPolicyDocumentsControl.PolicyNumber = button.CommandArgument;
                    policySummaryPlaceHolder.Controls.Add(uxPolicyDocumentsControl);
                }
            }
        }
    }

My plan for the toggle was that if the PolicyDocuments control was null, then load the control, and if not then remove the control, but it always came back null. It did load the control correctly though.

Here is the section of the repeater:

<ItemTemplate>
                    <tr>
                        <td>
                            <%#Eval("StartDate","{0:d}")%>
                        </td>
                        <td class="center-cell-ctrl">
                            Postcode:<br />
                            <%#Eval("Postcode")%>
                        </td>
                        <td id='<%#Eval("PolicyNumber")%>' class="button-cell">                                
                            <asp:LinkButton ID="uxPolicyDocsButton" CommandName="PolicyNumber" CommandArgument='<%#Eval("PolicyNumber")%>' OnCommand="uxPolicyDocsButton_Command"  runat="server" Visible="false">Policy<br />Documents</asp:LinkButton>
                        </td>
                    </tr>
                    <asp:PlaceHolder ID="uxPolicySummaryPlaceHolder" runat="server"></asp:PlaceHolder>
                    <asp:PlaceHolder ID="uxPolicyDocumentsPlaceHolder" runat="server"></asp:PlaceHolder>

        </ItemTemplate>

I’ve had a look around for people who have had similar problems, and a common answer is that you need to load controls in the Page_Init event. Does that mean that this way won’t work? Any ideas for an alternative if this is the case?

Many thanks

  • 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-23T05:24:33+00:00Added an answer on May 23, 2026 at 5:24 am

    I dont’ understand, why you can’t add the PolicyDocuments with visible = false and no datasource instead of Placeholder, like that:

    <uc:PolicyDocuments ID="uxPolicyDocuments" runat="server" Visible="false"></asp:PolicyDocuments>
    

    and during the command use such code:

            if (ri != null)
            {
                var policyDocuments = ri.Controls.OfType<PolicyDocuments>().FirstOrDefault();
                if (policyDocuments == null)
                    return;
    
                if (policyDocuments.Visible)
                {
                    policyDocuments.Visible = false;
                }
                else
                {
                    policyDocuments.PolicyNumber = button.CommandArgument;
                    policyDocuments.Visible = true;
                }
            }
    

    In this case you don’t need to use some hacks in Init event of the page.
    Anyway, you always can use the .Controls.OfType<PolicyDocuments>() extension method to get all the user controls you need.

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

Sidebar

Related Questions

I have a repeater that is looping a user control, like this: <asp:Repeater ID=repItems
I have a repeater that holds a Radio button list, a textbox and a
I have an ASP.NET repeater that shows a list of items with a delete
i have a repeater that will output a series of items: <asp:repeater ... runat=Server>
I have a repeater control that contains an ItemTemplate containing a databound label and
I have a Repeater control that is being bound to the result of a
I have a Repeater control that loads instances of a custom control I have
Greetings! I have a Repeater control that's using an XmlDataSource control. <asp:FormView id=myFormView runat=server
I have Repeater Control and in that i have code like this <div runat=server
I have a Repeater control that is creating a dynamic amount of CheckBoxList controls

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.