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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:24:11+00:00 2026-06-08T21:24:11+00:00

Disclaimer: I have read the ASP.net page life cycle , and I’ve also read

  • 0

Disclaimer: I have read the ASP.net page life cycle, and I’ve also read several good articles pertaining to dynamic controls, but I must be missing something.

Background: I am currently working on a website which needs to create a lot of dynamic content based on the user’s input. I understand that, in order for dynamic controls to persist and for their events to wire up correctly, I need to re-create those dynamic controls on every page post-back.

Because of the nature of my project, my code doesn’t know WHAT controls to create unless it has some information about what the user selected. I’m storing the user’s choices in the ViewState, which is unavailable in Page_Init because it has not yet loaded. Consequently, I have to wait until Page_PreLoad or Page_Load to read the ViewState and then re-create my dynamic controls.

The part I don’t understand: When I try re-creating my controls during Page_Load, the controls persist but the associated events don’t seem to fire. For example, clicking on a LinkButton I created does not fire the method that I wired to its Click event, even though the button itself does persist.

A strange solution that I discovered by accident is that I can instead re-create my controls during Page_PreLoad and then the events fire correctly.

My question (or questions, rather): Why does my problem appear to go away by re-creating my controls during Page_PreLoad instead of Page_Load? Is this a safe practice? I’ve never seen any other code that used Page_PreLoad, which makes me wary. This solution is working for me, but are there any pitfalls I might be missing? Am I unknowingly setting myself up for failure later on?

My code, where LoadDocument() is a method that creates controls and stuffs them into a static Panel control:

protected void Page_PreLoad(object sender, EventArgs e)
{
    if (ViewState["xmlfilename"] != null)
    {
        LoadDocument(ViewState["xmlfilename"].ToString());
    }
}
  • 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-08T21:24:12+00:00Added an answer on June 8, 2026 at 9:24 pm

    Your events are processed during the ProcessPostData. Which control triggered the postback, too is post data. If your control does not exist at that time, it will not receive the event.

    I agree Init would be too early, and Load too late.

    What you need to do here is create these controls as soon as your view state is loaded.

    There is no event for this in the Page life cycle. However all the functions being virtual, you can override the functions called in between.

    The best place to load such controls that depend on values stored in the ViewState is the LoadViewState function.

    • Override this function.
    • Remember to call base.LoadViewState at the very start.
    • Create your controls depending on the ViewState values.

    Now all your controls events should fire properly.

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

Sidebar

Related Questions

Disclaimer: Never used php in my life. New to Unix and Jenkins I have
i have a disclaimer tick box on my login page and i want to
Disclaimer: first month of developing with rails, but I have read everything I could
Disclaimer : I'm a c# ASP.NET developer learning RoR. Sorry if this question doesn't
Disclaimer: I have no Twitter API experience nor have I used Twitter until today
Disclaimer: I have not used RoR, and I have not generated tests. But, I
Disclaimer: absolute novice in Scala :( I have the following defined: def tryAndReport(body: Unit)
Disclaimer I am well aware that PHP might not have been the best choice
I have a WPF sorting/binding issue. (Disclaimer: I am very new to WPF and
DISCLAIMER: I know there is debate between DI and service locator patterns. I have

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.