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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:00:05+00:00 2026-06-19T01:00:05+00:00

On an ASP.NET web page, I have an UpdatePanel. Inside this UpdatePanel, I have

  • 0

On an ASP.NET web page, I have an UpdatePanel. Inside this UpdatePanel, I have an “Add” button which dynamically adds any number of a User Control that I have created to a PlaceHolder. The User Control contains a label, a button, and a 3rd-party control. The button inside the User Control is for removing that particular User Control from the parent panel. Both the “Add” and “Remove” functionality work correctly. However, the event handler on the Add button sometimes stops working with no apparent pattern or cause. If I add 2 UCs and remove 1, sometimes the Add button continues to work and sometimes it doesn’t. Any step toward finding a cause would be helpful.

For context, the UCs are called “Whereas” because they are WHEREAS clauses in resolutions. Here is the code, cut down to relevant content only:

Edit.aspx

...
<asp:ScriptManager ID="sm1" runat="server"></asp:ScriptManager>
<asp:Panel ID="pnlMain" runat="server">
    <div class="form-horizontal">
        <asp:UpdatePanel ID="upnlWhereas" runat="server">
            <ContentTemplate>
                <asp:PlaceHolder ID="phWhereas" runat="server"></asp:PlaceHolder>
                <div class="control-group">
                    <asp:Label ID="lblAddWhereas" AssociatedControlID="btnAdd1Whereas" CssClass="control-label" runat="server"></asp:Label>
                    <div class="controls">
                        <asp:Button ID="btnAdd1Whereas" CssClass="btn" UseSubmitBehavior="false" Text="Add Whereas" runat="server" />
                    </div>
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
</asp:Panel>
...

Edit.aspx.vb (class is Edit2)

...
Private Property ControlsList As List(Of String)
    Get
        If ViewState("ControlsList") Is Nothing Then
            ViewState("ControlsList") = New List(Of String)
        End If

        Return CType(ViewState("ControlsList"), List(Of String))
    End Get
    Set(ByVal Value As List(Of String))
        ViewState("ControlsList") = Value
    End Set
End Property

Private ReadOnly Property NextID As Integer
    Get
        Return ControlsList.Count + 1
    End Get
End Property

Protected Overrides Sub LoadViewState(savedState As Object)
    MyBase.LoadViewState(savedState)

    For Each waID As String In ControlsList
        Dim NewWhereas As Whereas
        NewWhereas = Me.LoadControl("~/UserControls/Whereas.ascx")

        NewWhereas.ID = waID
        phWhereas.Controls.Add(NewWhereas)

        AddHandler NewWhereas.OnRemoveWhereasClick, AddressOf Whereas_OnRemoveWhereasClick
    Next
End Sub

...

Private Sub btnAdd1Whereas_Click(sender As Object, e As System.EventArgs) Handles btnAdd1Whereas.Click
    Dim NewWhereas As Whereas
    NewWhereas = Me.LoadControl("~/UserControls/Whereas.ascx")

    NewWhereas.ID = "wa" + NextID.ToString
    phWhereas.Controls.Add(NewWhereas)

    ControlsList.Add(NewWhereas.ID)
End Sub

Private Sub Whereas_OnRemoveWhereasClick(ByVal sender As Object)
    Dim thisButton As Button = sender
    Dim thisWhereas As Whereas = thisButton.Parent.Parent

    phWhereas.Controls.Remove(thisWhereas)
    ControlsList.Remove(thisWhereas.ID)
End Sub
...

Whereas.ascx.vb

Public Delegate Sub ActionClick(ByVal sender As Object)

Public Class Whereas
    Inherits System.Web.UI.UserControl

    ...

    Public Event OnRemoveWhereasClick As ActionClick

    Public Sub btnRemoveWhereas_Click(ByVal sender As Object, ByVal e As EventArgs)
        RaiseEvent OnRemvoeWhereasClick(sender)
    End Sub
End Class
  • 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-19T01:00:07+00:00Added an answer on June 19, 2026 at 1:00 am

    After disabling the UpdatePanel (thanks to Yellowfog for the suggestion), I found that the following was happening:

    1. Clicking “Add” would add a user control with ID “wa1.”
    2. Clicking “Add” again would count the number of existing user controls in the list and add a user control with ID “wa2.”
    3. Clicking “Remove” on control “wa1” would remove “wa1.”
    4. Clicking “Add” would count the number of existing user controls in the list (1) and attempt to add a user control with ID “wa2” which would cause an error because that control already exists on the page. This error wasn’t being displayed because the call was asynchronous.

    The solution was to generate the IDs of the dynamically-added user controls using GUIDs instead of integers based on the number of controls in the list. This way they are essentially guaranteed to be unique.

    • 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 web page, which uses a Master Page template. The page
I have a standard ASP.NET 2.0 web page with a Delete button on it.
I have a ASP.NET web application which has more than 100 pages. Each page
i have an updatepanel in my asp.net web page. I want to trigger the
I have an asp.net web application, in that I want to add a page
On an ASP.NET web page I have an EntityDataSource: <asp:EntityDataSource ID=EntityDataSourceOrders runat=server ConnectionString=name=EntitiesContext DefaultContainerName=EntitiesContext
I have an ASP.NET web page(Not MVC ) (HomePage.aspx) and another page (PRiceList.aspx).I have
I have a ASP.NET web page that contains many textboxes. Each textbox has a
I have an asp.net web page (C# 2008) where the user would enter an
I have to do a asp.net web page that when load will say something

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.