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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:19:34+00:00 2026-06-08T17:19:34+00:00

I have a situation where I’m using some markup in 2 places on a

  • 0

I have a situation where I’m using some markup in 2 places on a page, one of which is in a repeater. The one in the repeater is not initializing its child controls; they’re staying null.

Default.aspx:

<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="nestedcontroltest._Default" %>
<%@ Register TagPrefix="a" Namespace="nestedcontroltest" Assembly="nestedcontroltest" %>
<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <asp:Repeater runat="server" ID="rptLetters" OnItemDataBound="rptLetters_ItemDataBound">
            <ItemTemplate>
                <a:MyControl runat="server" ID="ctrlMyControl"/>
            </ItemTemplate>
        </asp:Repeater>
    </body>
</html>

Default.aspx.cs:

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        rptLetters.DataSource = new[] { "a", "b", "c" };
        rptLetters.DataBind();
    }

    public void rptLetters_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        var ctrlMyControl = (MyControl)e.Item.FindControl("ctrlMyControl");
        ctrlMyControl.Text = e.Item.DataItem.ToString();
    }
}

MyControl.ascx:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyControl.ascx.cs" Inherits="nestedcontroltest.MyControl" %>
<asp:Panel runat="server" ID="pnlContent">
    <asp:Literal runat="server" ID="ltlText"/>
</asp:Panel>

MyControl.ascx.cs:

public partial class MyControl : UserControl
{
    public string Text { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {
        ltlText.Text = Text;
    }
}

When I try to load this, I get “Object reference not set to an instance of an object.” – apparently ltlText is null.

How can I get my UserControl to initialize properly?

  • 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-06-08T17:19:36+00:00Added an answer on June 8, 2026 at 5:19 pm

    Found the answer:

    1. The repeater had nothing to do with the problem.
    2. In Default.aspx, I needed to register the control by name rather than by namespace.

      <%@ Register TagPrefix="a" Namespace="nestedcontroltest" Assembly="nestedcontroltest" %>
      

      Needs to be changed to

      <%@ Register TagPrefix="a" TagName="MyControl" Src="~/MyControl.ascx" %>
      

    And then the control gets initialized properly, even when it’s in the repeater. Perhaps a bug in ASP.net, or perhaps I needed to use the full assembly name? Regardless, thanks for all your help guys.

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

Sidebar

Related Questions

i have situation in which i have some library projects, say DataProcessors,Lib2 , included
I have a situation where I'm serializing some .NET objects using NetDataContractSerializer and storing
I have situation in which I read a record from a database. And if
I have situation where I have to call method of interface using reflection, like
I have situation in which i'm compelled to retrieve 30,000 records each to 2
I have situation where a 3rd party open source product I am using is
Possible Duplicate: What is my script src URL? I have situation: <script type=text/javascript src=http://server/some.js>
I have a situation where there is a program which is written in c++.
I have a situation (using the Raphael library) where I have this: rect.click(doSomething); And
I have a situation in which I need to extract Data Annotations information from

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.