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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:02:59+00:00 2026-05-27T14:02:59+00:00

I have an ASP.NET user control with a button, and I want to add

  • 0

I have an ASP.NET user control with a button, and I want to add it to the page when the user clicks a button from another user control. I have created an event handler to the first user control to handle it from the page and add the second user control to a page. Everything is working normally, but the button on the second user control doesn’t respond to the event.

I place the second control on RadAjaxPanel

Note: When I add the second user control at design time its working fine.

  • 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-27T14:03:00+00:00Added an answer on May 27, 2026 at 2:03 pm

    All dynamically created controls should be added by the end of Page_Init (though sometimes you can get away with them added by the end of Page_Load).

    If you’re only adding them based on a button click event then you’ve done this in the event handers which fire AFTER Page_Init and Page_Load in the lifecycle – This is why your events don’t fire and why it works fine when you add at design time.

    This is because when a button is clicked on the second user control – the whole page lifecycle starts again. The page goes through Page_Load and Page_Init first and your control doesn’t get loaded here. So, when the page lifecycle handles the “handle postback events” part, the control no longer actually exists, so the event doesn’t fire.

    Conversely, when you add at design time, the control exists in Page_Init and Page_Load so is able to handle the postback events from the user control because it already exists in the control tree – if this makes sense.

    You need to think how you can restructure so they’re added by the time Page_Load has finished at the very latest or it won’t work. Without code samples or more detail it’s hard to suggest exactly how you might do this. One possibility would be to set it visible instead of loading it outright – but if the control does some ‘heavy lifting’ on load like database hits or API calls then this might not be suitable for you.

    I did something similar. What I did was to load some controls dynamically based on a selection from a DropDownList. If you have a method which loads the control for you, let’s call it LoadControls(), then you can do something like this:

    DropDownList_Click {
     ViewState("LoadControls") = true;
     LoadControls()
    }
    

    By setting the ViewState variable, you can then indicate Page_Load to load the controls on future postbacks:

    Page_Load {
     if (ViewState("LoadControls") == "true")
     {
      LoadControls();
     }
    }
    

    This has the effect of then loading the control on-the-fly when the event first happens, and then at future times in the lifecycle.

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

Sidebar

Related Questions

I have an ASP.NET user control (.ascx file). In this user control I want
I have an asp.net user control on which I want to use jquery ajax.
I have an asp.net user control, userControl1.ascx, and another user control, userControl2.ascx. userControl2 is
I have an ASP.NET page which has an asp.net button control in it. When
I have an asp.net TextBox control on my page and a search button whenever
I have an asp.net button control on the page. <asp:Button ID=btnFinishReceiving runat=server Text=Finished Receiving
I have an ASP.NET user control that contains a text box control and a
I have a ASP.NET user control which hosts a 'HtmlImage'. The src attribute is
I have an ASP.Net web user control that contains a TextBox and a calendar
I have a asp.net usercontrol (.ascx). the user control has a HTML hidden field.

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.