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 1109869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:18:21+00:00 2026-05-17T02:18:21+00:00

If I have a custom user control (say, MyCustomControl.ascx) which contains a number of

  • 0

If I have a custom user control (say, MyCustomControl.ascx) which contains a number of other controls including a repeater, is there any way to expose that repeater’s templates as templates for MyCustomControl?

For example, I would want to be able to do this:

<uc:MyCustomControl ID="MyCustomControl1" runat="server">
    <ChildRepeaterHeaderTemplate>
        <!-- code goes here -->
    </ChildRepeaterHeaderTemplate>
    <ChildRepeaterItemTemplate>
        <!-- code that accesses values on the repeater's DataItem goes here -->
    </ChildRepeaterItemTemplate>
    <ChildRepeaterFooterTemplate>
        <!-- code goes here -->
    </ChildRepeaterFooterTemplate>
</uc:MyCustomControl>

There could potentially be more than one repeater or other templated controls within the parent control, in which case I would like to be able to expose all of those templates for all of the controls in the same way.

My first thought was to simply expose the repeater’s templates as ITemplate properties on MyCustomControl, but that didn’t work since there’s no (obvious) way to access the repeater’s DataItem from the templates doing it that way.

  • 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-17T02:18:21+00:00Added an answer on May 17, 2026 at 2:18 am

    Like Brian says, you need a custom control, but if you had that, you could expose the ItemTemplates.

    namespace MyControls
    {
        public class MyControl : System.Web.UI.WebControls.WebControl
        {
            System.Web.UI.WebControls.Repeater FirstRepeater = new System.Web.UI.WebControls.Repeater();
            System.Web.UI.WebControls.Repeater SecondRepeater = new System.Web.UI.WebControls.Repeater();
    
            [System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
            public System.Web.UI.ITemplate FirstTemplate
            {
                get
                {
                    return FirstRepeater.ItemTemplate;
                }
                set
                {
                    FirstRepeater.ItemTemplate = value;
                }
            }
    
            [System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
            public System.Web.UI.ITemplate SecondTemplate
            {
                get
                {
                    return SecondRepeater.ItemTemplate;
                }
                set
                {
                    SecondRepeater.ItemTemplate = value;
                }
            }
    
            protected override void CreateChildControls()
            {
                base.Controls.Add(FirstRepeater);
                object[] FirstDataSource = {
                    new { x = "1" },
                    new { x = "2" },
                    new { x = "3" },
                    new { x = "4" }
                };
                FirstRepeater.DataSource = FirstDataSource;
                FirstRepeater.DataBind();
    
                base.Controls.Add(SecondRepeater);
                object[] SecondDataSource = {
                    new { y = "a" },
                    new { y = "b" },
                    new { y = "c" },
                    new { y = "d" }
                };
                SecondRepeater.DataSource = SecondDataSource;
                SecondRepeater.DataBind();
    
                base.CreateChildControls();
            }
        }
    }
    

    You need to instantiate your child repeaters before the control that includes this one tries to assign them.
    This sample creates two child repeaters inside the control and binds them to some dummy data.

    And with a page that uses this control:

    <%@ Page %>
    
    <%@ Register Namespace="MyControls" TagPrefix="mc" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form runat="server">
        <div>
            <mc:MyControl runat="server">
                <FirstTemplate>
                    <div style="color: blue">
                        <%# Eval("x")%>
                    </div>
                </FirstTemplate>
                <SecondTemplate>
                    <div style="color: red">
                        <%# Eval("y")%>
                    </div>
                </SecondTemplate>
            </mc:MyControl>
        </div>
        </form>
    </body>
    </html>
    

    You get the following output:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head><title> 
    
    </title></head> 
    <body> 
        <form method="post" action="" id="ctl01"> 
    <div class="aspNetHidden"> 
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTEwMjEyMzEwMzcPZBYCAgMPZBYCAgEPZBYEZg8WAh4LXyFJdGVtQ291bnQCBBYIZg9kFgJmDxUBATFkAgEPZBYCZg8VAQEyZAICD2QWAmYPFQEBM2QCAw9kFgJmDxUBATRkAgEPFgIfAAIEFghmD2QWAmYPFQEBMmQCAQ9kFgJmDxUBAWJkAgIPZBYCZg8VAQFjZAIDD2QWAmYPFQEBZGRk7v0uzzMp0h89eUJash2eToIH2EboQLSZWnkVYXRsGpM=" /> 
    </div> 
    
        <div> 
            <span> 
                    <div style="color: blue"> 
                        1
                    </div> 
    
                    <div style="color: blue"> 
                        2
                    </div> 
    
                    <div style="color: blue"> 
                        3
                    </div> 
    
                    <div style="color: blue"> 
                        4
                    </div> 
    
                    <div style="color: red"> 
                        a
                    </div> 
    
                    <div style="color: red"> 
                        b
                    </div> 
    
                    <div style="color: red"> 
                        c
                    </div> 
    
                    <div style="color: red"> 
                        d
                    </div> 
                </span> 
        </div> 
        </form> 
    </body> 
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created Custom User Control which contain TextBox and PasswordBox. it is binding
I have a custom user control UserProfileLink on which I have two basic string
Let's say I have a custom control which wraps another control (for example MyCustomButton).
Let's say I have an ASCX user control that requires access to the current
I have a custom user control that contains asp:ValidationSummary . It is placed on
I have a custom user control which has some textboxes and some buttons. In
I have a custom user control extending the Listbox class. Inside of it I
I have a custom user control on my windows forms. This control has a
I have a custom user control called ErrorNotificationBox. To place that on my page
I have a custom base user control in silverlight. <UserControl x:Class=Problemo.MyBaseControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:d=http://schemas.microsoft.com/expression/blend/2008

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.