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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:53:38+00:00 2026-05-23T13:53:38+00:00

I find this as a funny little problem. I think the reason lies behind

  • 0

I find this as a funny little problem. I think the reason lies behind the life-cycle of page-object/events-generation, but the question is how I come around the problem?

In Default.aspx there exist some funny controls but also a
<asp:PlaceHolder runat="server" id="phUserContent"></asp:PlaceHolder>

This placeholder is empty until runtime. Code behind are, in some circumstances, loading UserControls into it. Like this
Control ctr = LoadControl("~/UserControl/Note.ascx");
phUserContent.Controls.Add(ctr);

This Note.ascx contains some interesting controls and finally a LinkButton that fires an event. The LinkButton-code are very easy and gramatically correct,
<asp:LinkButton runat="server" ID="lbUpdate" OnClick="lbUpdate_Click" Text="Update"></asp:LinkButton>

In the Code behind for the ascx I have the code for the event,

protected void lbUpdate_Click(object sender, EventArgs e)
{ ... }

As I wroted, the postback occurs, the page are regenerated as I would suspect – but without the lbUpdate_Click event to be executed. A break-point is of course tried.

I’m looking for two possible scenarios. One is that I missed something really easy (you know, like wroted in wrong code behind file) or that I missed an important part of the Page Generation Cycle.

I’m mostly into the second, like this (i just think here..)
1. Page (ascx) got it’s changes
2. Submit was clicked
3. Ascx was re-generated
4. Events was cleared but was exist and doesnt cast error.
5. After reload, initial content was reloaded

The effect would be that the compiler can’t see the breakpoint and the values was never saved due to a “execution of an empty event”. But this is just a amateours guess, please advice me.

[UPDATE AS PER ANSWER]
This is how I was solved it, based on the acepted answer below.

List<Control> ctr;
public User()
{
    ctr = new List<Control>();
}
protected void Page_PreInit(object sender, EventArgs e)
{
    ctr.Add(LoadControl("~/UserControl/Note.ascx"));
}

protected void Page_Load(object sender, EventArgs e)
{
    ctr.ForEach(d => phUserContent.Controls.Add(d));
}

Shortly..
1. The class got a list of Controls
2. In Page_PreInit (before creation) add UC (u can have X of them here)
3. In Page_Load (where all ctr are created) add each UC to the PH.

Which also make the events in the UC also working, no magic and no dumb complications 🙂

  • 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-23T13:53:38+00:00Added an answer on May 23, 2026 at 1:53 pm

    It’s a lifecycle issue.

    Remember, every page request creates a new Page object, and new instances of all the controls on it. If you are dynamically creating a control, then it has to be done in the exact same manner on every postback. If you want the new control to fire an event, then it has to have the same id as the old one, and have the event hooked up to it before control events are processed in the lifecycle.

    If you’re creating the control dynamically at a point in the page lifecycle that occurs after ViewState is handled, then you’ll have to manage your own state as well. In other words, if you’re not dynamically creating the control during the PreInit phase, then you’ll have to manually deal with restoring state.

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

Sidebar

Related Questions

I find this question a little tricky. Maybe someone knows an approach to answer
I couldn't find this in the documentation. If I have a complex object in
I'm trying to find a solution for this problem. This is my example code:
I got some funny but annoying problem. Somehow I toggled this kind of view
coders. I'm running a little problem here and can't find the solution. I'm building
I know this is pointless: I just find it funny and I want to
I find this feature of automatic selection to item index 0 in the Listbox
I find this article to be useful for non-ajax request How to handle session
I find this pretty confusing. When you want to rotate a view, it's going
i find this question tricky but what files store method signature info for xml

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.