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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:05:50+00:00 2026-05-26T21:05:50+00:00

I have a UserControl which uses a UserControl, among other controls. In the ascx

  • 0

I have a UserControl which uses a UserControl, among other controls.

In the ascx file I have the following code:

<%@ Register TagPrefix="tag" Namespace="some.name.space" Assembly="some.assembly" %>
<tag:control ID="test" runat="server" />

In my Page_Load method, I try to set a property on test like so:

test.Text = "Hello World!";

This actually sets the Text property of a literal control in my user control test.

This throws an exception:

Object reference not set to an instance of an object

When it tries to set the

lblTest.Text = value; 

The object that is null is lblTest.

Am I not adding the user control correctly? Should I – or do I have to – specify the Src property when registering a Tag? If so, I’d have to register every usercontrol I use?

This also results in no controls loading in usercontrol and all controls are null within usercontrol.

  • 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-26T21:05:50+00:00Added an answer on May 26, 2026 at 9:05 pm

    If the user control is in your current project, then you need to include the src in the register statement:

    <%@ Register TagPrefix="uc1" TagName="NavTop" Src="controls/NavTop.ascx" %>
    

    However, if you use this user control in more than one page, then you can also register it in web.config:

    <system.web>
      <pages>
        <controls>
          <add tagPrefix="uc1" tagName="NavTop" src="~/controls/NavTop.ascx" />
        </controls>
      </pages>
    </system.web>
    

    One other thing to be aware of: there are times when the visual studio designer does not “see” your changes to controls on the page if you only make the changes in source view. If you change a control name, for example, you could end up with a control with the new name in the ascx but a reference to a control with the old name in the designer file. At runtime, this will result in the designer file property being null.

    After having been burnt by this a number of times, if I make any changes in source view, I either check to see that the designer file has been updated correctly or I switch to design view, make a minor change, then save the page/user control.

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

Sidebar

Related Questions

I have a UserControl which I have added to my web.config <add tagPrefix=BCF src=~/controls/MyMessageBox.ascx
The problem: I have a UserControl (LightBox) which overlays a number of other controls
I have a user control which uses objects as inner properties (some code is
I have a Silverlight UserControl which uses the ContentPropertyAttribute to exposes the Children property
I have a Silverlight Usercontrol where I have a tabcontrol which uses a couple
I have a custom UserControl which uses a simple ITemplate: <asp:Panel runat=server ID=pnlExpander CssClass=expander>
I have a UserControl which overrides the OnRender-Method as follow: MyUsercontrol.cs: MyUserControl: UserControl {
I have a UserControl which contains a TextBox . When my main window loads
Hi I have a usercontrol which includes some JavaScript, if I add the control
I have a UserControl A which contains a dropdown a placeholder At runtime the

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.