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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:10:59+00:00 2026-05-16T20:10:59+00:00

I have a very weird issue. I have a UserControl that has some controls

  • 0

I have a very weird issue. I have a UserControl that has some controls inside. I want to refer those controls after, in another postback. But when I try to get them the Controls property of my controls returns null.
I’m working on vs2008.

Here is the sample code:

public partial class MyUserControl : System.Web.UI.UserControl, INamingContainer
{
    protected void Page_Load(object sender, EventArgs e)
    {
        foreach (Control control in this.Controls)
        {
            Response.Write(control.ClientID);
        }
    }

    private void MyTable()
    {
        Table table = new Table();
        TableRow row = new TableRow();
        TableCell cell = new TableCell();

        CheckBox check = new CheckBox();
        check.ID = "theId";
        check.Text = "My Check";
        check.AutoPostBack = true;
        cell.Controls.Add(check);
        row.Cells.Add(cell);

        check = new CheckBox();
        check.ID = "theOther";
        check.AutoPostBack = true;
        check.Text = "My Other Check";

        cell = new TableCell();
        cell.Controls.Add(check);
        row.Cells.Add(cell);

        table.Rows.Add(row);
        this.Controls.Add(table);
    }

    protected override void Render(HtmlTextWriter writer)
    {
        MyTable();
        base.Render(writer);
    }
}

and the Default.aspx page is something like:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.cs" Inherits="Tester.Default" %>
<%@ Register TagPrefix="uc1" TagName="MyControl" Src="~/MyUserControl.ascx" %>

<!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>Unbenannte Seite</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <uc1:MyControl ID="MyControlInstance" runat="server" />
    </div>
    </form>
</body>
</html>

I don’t know if I’m lost in some part of the ASP.NET life cycle. But this situation is making me crazy. Any help would be very grateful.

  • 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-16T20:11:00+00:00Added an answer on May 16, 2026 at 8:11 pm

    Create your child controls (MyTable) in either CreateChildControls or OnInit:

    protected override void CreateChildControls()
    {
        MyTable();
        base.CreateChildControls();
    }
    

    Or

    protected override void OnInit(object sender, EventArgs e) 
    {
        MyTable();
        base.OnInit(e);
    }
    

    You shouldn’t/cannot create controls in Render as it occurs after Page_Load. See the ASP.Net Page Lifecycle here.

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

Sidebar

Related Questions

I have seen some very weird for loops when reading other people's code. I
I have a weird issue that only seems to be affecting IE 7. The
We have a very lengthy newsletter that has been designed and developed to look
I have a very weird problem: sometimes when I call nHibernate update to an
i have very simple problem. I need to create model, that represent element of
I have a very strange problem. Under some elusive circumstances I fail to apply
I have a very large code base that contains extensive unit tests (using CppUnit).
I'm having a very weird issue with the command line and running Ant. I
I am having a very weird issue with templates. Getting an error error: ‘traits’
I have a very weird problem with PROLOG. I have used it before, but

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.