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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:18:38+00:00 2026-05-29T05:18:38+00:00

I have an ASP.NET web form on which I’m displaying a list of database

  • 0

I have an ASP.NET web form on which I’m displaying a list of database items via user controls, generating the user controls dynamically – working fine.

Also on the page, I have an asp:dropdownlist filled with items that can be added to this database list. Along with this dropdown I have a button ‘ADD’. My intent is that the user chooses and item, clicks add, and then the list of user controls on the form will include this new item.

I have all this working.

My issue is that the user control has a button ‘DELETE’, which removes the selected item from the list. That works, EXCEPT when I add a new item. Because my ‘add’ button event is always fired after Page_Load, even if I regenerate the list of user controls, the internal user control click events won’t fire because the controls weren’t created as part of Page_Load.

I need to know what I’m doing wrong, or best practices here, any advice. I tried to be precise in the description of the problem, but if I’ve not succeeded, let me know and I can add more details.

SIMPLE RESTATE: I need to know how to add a dynamically created user control to a page via a page button click event, and still have the user control internal click(etc) events firing.

Thanks for any help.

EDIT: Based on the feedback from the gentlemen here, and doing some further research related to their suggestions, I ended up implementing a solution based on what’s presented on this page:

http://ryanfarley.com/blog/archive/2005/03/11/1886.aspx

Here’s a snippet showing how I dealt with this. This snippet resides in my PreInit event handler. Not exactly an elegant weapon for a civilized age, but sometimes a blaster is all you’ve got to use.

'Look to see if button for adding a new client number has been
'clicked.  If so, call the sub to add the item NOW, so that it
'is able to have it's internal click events fire.
For Each control_string As String In Request.Form
  Dim ctl As Control = Page.FindControl(control_string)

  If (ctl IsNot Nothing) AndAlso (ctl.ID = "cmdAddClientNumber") Then
    Me.AddClientNumberToList()
    Exit For
  End If
Next
  • 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-29T05:18:38+00:00Added an answer on May 29, 2026 at 5:18 am

    On the button handler, you initially add the UserControl to the Page. OnPreInit (which will next be fired when the user clicks Delete on the UserControl), you should re-add the UserControl – so that it exists, and can handle the Delete button event.

    You will need to devise your own state tracking mechanism to determine that you need to add the UserControl during PreInit. I generally use ViewState, as evidenced by this seemingly similar post.

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

Sidebar

Related Questions

In my ASP.NET Web-form Project I have an Event which Export Data ( List<Profit>
I have an ASP.NET web form which I am adding a variable number User
I have a asp.net web form which will submit information to come as emails.
I have details view control in my asp.net web form, which on of its
Here's the problem I'm having in my ASP.NET web-form project. I have Datalist which
I have a GridView on ASP.NET web form which I have bound to a
I have simple web application (asp.net - ajax) I have a web form which
I have a web form of Asp.Net, in which I want JavaScript to count
I have a windows form application(c#) and an asp.NET web application which both access
I have an asp.net url path which is being generated in a web form,

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.