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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:41:20+00:00 2026-05-19T14:41:20+00:00

I have a page with a ScriptManager, a generic HTML drop-down list ( <select>

  • 0

I have a page with a ScriptManager, a generic HTML drop-down list (<select>), and an UpdatePanel. The UpdatePanel contains a PlaceHolder (for now). During Page_Load, a number of user controls are added to the PlaceHolder (really, it’s several instances of the same user control). The number to add is not known until the page loads, so they do need to be loaded dynamically. The drop-down list is populated with the same number of menu items, and there is javascript on the page also (using jQuery) to show only one of the controls at a time depending on the state of the drop-down list.

Each user control has two buttons that should generate an asynchronous postback, a drop-down list that should generate an asynchronous postback on a change in selected value, and a button that should generate a synchronous postback. If I was not generating the controls dynamically, and if there was only one control, the structure would be something like:

<asp:UpdatePanel ID="myUpdatePanel" runat="server" UpdateMode="Conditional"
                 ChildrenAsTriggers="false">
    <ContentTemplate>
        <asp:TextBox ID="textBox1" runat="server" />
        <asp:TextBox ID="textBox2" runat="server" />
        <asp:Button ID="asyncButton1" runat="server" Text="Button1"
                    onclick="asyncButton1_Click" />
        <asp:DropDownList ID="asyncDropDown" ruant="server" AutoPostBack="true"
                    OnSelectedIndexChanged="asyncDropDown_SelectedIndexChanged" />
        <asp:Button ID="asyncButton2" runat="server" Text="Button2"
                    OnClick="asyncButton2_Click" />
        <asp:Button ID="syncButton" runat="server" Text="SyncButton"
                    OnClick="syncButton_Click" />
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="asyncButton1" EventName="Click" />
        <asp:AsyncPostBackTrigger ControlID="asyncButton2" EventName="Click" />
        <asp:AsyncPostBackTrigger ControlID="asyncDropDown"
            EventName="SelectedIndexChanged" />
        <asp:PostBackTrigger ControlID="syncButton" />
    </Triggers>
</asp:UpdatePanel>

Of course, all the controls inside the ContentTemplate would actually be part of each user control.

Adding the triggers on the server side does not seem to work because no ControlID seems to help the UpdatePanel find the relevant controls. I can use either the control’s ID or the control’s UniqueID, and it does not work, and I get an error along the lines of

A control with ID 'ctl00$ContentPlaceHolder1$ctl01$asyncButton1' could not be
found for the trigger in UpdatePanel 'myUpdatePanel'.

So, I wonder if I need to register the triggers in the client instead using ASP.NET Ajax. I found this page that basically explains how. However, I do not know how to get the EventName taken into consideration. The examples I have seen so far have merely been adding button clicks, but I don’t know how to handle the SelectedIndexChanged event from the DropDownList.

Any help here? Are there examples out there I have missed? It doesn’t help, of course, that the method in the link I gave appears to be “unofficial,” so I don’t see any MSDN documents on the subject.

Thanks!

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

    My suggestion would be to pull all your controls inclusive this UpdatePanel out of this UpdatePanel into an UserControl. Define events in your usercontrol that are raised when the buttons are clicked or the Dropdown’s selected index get changed. Handle these events in your page that holds the Placeholder(in a single UpdatePanel,conditional,without triggers). Call the Update-method of the main update panel manually if you add UserControls.

    To clarify what i mean have a look at following example:

    Main-page aspx:

    <asp:UpdatePanel ID="Upd1" runat="server" UpdateMode="Conditional">
      <ContentTemplate>
         <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
      </ContentTemplate>
    </asp:UpdatePanel>
    

    Codebehind:

      Private Property UserControlCount() As Int32
            Get
                If ViewState("UserControlCount") Is Nothing Then
                    ViewState("UserControlCount") = 1
                End If
                Return DirectCast(ViewState("UserControlCount"), Int32)
            End Get
            Set(ByVal value As Int32)
                ViewState("UserControlCount") = value
            End Set
        End Property
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            recreateUserControls()
        End Sub
    
        Private Sub recreateUserControls()
            For i As Int32 = 1 To Me.UserControlCount
                Dim uc As DynamicControls = DirectCast(Me.LoadControl("DynamicControls.ascx"), DynamicControls)
                uc.ID = "DynamicControls_" & i
                Addhandlers(uc)
                Me.PlaceHolder1.Controls.Add(uc)
            Next
        End Sub
    
        Private Sub Addhandlers(ByVal uc As DynamicControls)
            AddHandler uc.asyncButton1Clicked, AddressOf ucAsyncButton1Clicked
            AddHandler uc.asyncButton2Clicked, AddressOf ucAsyncButton2Clicked
            AddHandler uc.syncButtonClicked, AddressOf ucSyncButtonClicked
            AddHandler uc.asyncDropDownSelectedIndexChanged, AddressOf ucAsyncDropDownSelectedIndexChanged
        End Sub
    
        Private Sub addUserControl()
            Me.UserControlCount += 1
    
            Dim uc As DynamicControls = DirectCast(Me.LoadControl("DynamicControls.ascx"), DynamicControls)
            uc.ID = "DynamicControls_" & Me.UserControlCount
            Addhandlers(uc)
            Me.PlaceHolder1.Controls.Add(uc)
    
            Upd1.Update()
        End Sub
    
        Private Sub ucAsyncButton1Clicked(ByVal sender As Object, ByVal e As EventArgs)
            'only to demonstrate how to add control dynamically and update the UpdatePanel'
            addUserControl()
            Me.Upd1.Update()
        End Sub
    
        Private Sub ucAsyncButton2Clicked(ByVal sender As Object, ByVal e As EventArgs)
        End Sub
    
        Private Sub ucSyncButtonClicked(ByVal sender As Object, ByVal e As EventArgs)
        End Sub
    
        Private Sub ucAsyncDropDownSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
        End Sub
    

    ascx which holds your controls:

    <%@ Control Language="vb" AutoEventWireup="false" CodeBehind="DynamicControls.ascx.vb" Inherits="AJAXEnabledWebApplication1.DynamicControls" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
    
    <asp:UpdatePanel ID="myUpdatePanel" runat="server" UpdateMode="Conditional"
                     ChildrenAsTriggers="false">
        <ContentTemplate>
            <asp:TextBox ID="textBox1" runat="server" />
            <asp:TextBox ID="textBox2" runat="server" />
            <asp:Button ID="asyncButton1" runat="server" Text="Button1" />
            <asp:DropDownList ID="asyncDropDown" runat="server" AutoPostBack="true" />
            <asp:Button ID="asyncButton2" runat="server" Text="Button2" />
            <asp:Button ID="syncButton" runat="server" Text="SyncButton" />
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="asyncButton1" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="asyncButton2" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="asyncDropDown" EventName="SelectedIndexChanged" />
            <asp:PostBackTrigger ControlID="syncButton" />
        </Triggers>
    </asp:UpdatePanel>
    

    Codebehind of UserControl:

    Public Partial Class DynamicControls
        Inherits System.Web.UI.UserControl
    
        Public Event asyncButton1Clicked(ByVal sender As Object, ByVal e As System.EventArgs)
        Public Event asyncButton2Clicked(ByVal sender As Object, ByVal e As System.EventArgs)
        Public Event syncButtonClicked(ByVal sender As Object, ByVal e As System.EventArgs)
        Public Event asyncDropDownSelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    
        Private Sub asyncButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles asyncButton1.Click
            RaiseEvent asyncButton1Clicked(sender, e)
        End Sub
    
        Private Sub asyncButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles asyncButton2.Click
            RaiseEvent asyncButton2Clicked(sender, e)
        End Sub
    
        Private Sub syncButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles syncButton.Click
            RaiseEvent syncButtonClicked(sender, e)
        End Sub
    
        Private Sub asyncDropDown_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles asyncDropDown.SelectedIndexChanged
            RaiseEvent asyncDropDownSelectedIndexChanged(sender, e)
        End Sub
    End Class
    

    On this way you won’t have problems with ClientID’s.

    Addition:
    If you need access to the controls of your UserControls in the event-handlers, use one of following two options:

    1. cast the sender’s NamingContainer to the userControl’s type: Dim uc As DynamicControls = DirectCast(DirectCast(sender, Control).NamingContainer, DynamicControls)
    2. replace all occurences of (ByVal sender As Object, ByVal e As System.EventArgs) with (uc as DynamicControls). On this way the reference of your UserControl is added to the event as parameter and you could access public properties of it from the page, f.e.:

      dim txt1 as String = uc.Text1
      

    If you have exposed a property Text1 in the UserControl:

    Public Property Text1() As String
         Get
             Return textBox1.Text
         End Get
         Set(ByVal value As String)
             textBox1.Text = value
         End Set
     End Property
    

    The second option is the cleanest and most readable way.

    Update:
    According to your comment: you should place the UpdateProgress in the UserControl inside of the UpdatePanel that gets updated. Remember to set the AssociatedUpdatePanelID correctly. For example:

    <asp:UpdatePanel ID="UdpForm" runat="server" UpdateMode="conditional" ChildrenAsTriggers="false"  >
      <ContentTemplate>
        <asp:panel ID="FormPanel" runat="server">
            <asp:UpdateProgress ID="UpdateProgress1" DynamicLayout="true" runat="server" AssociatedUpdatePanelID="UdpForm" DisplayAfter="0" >
                <ProgressTemplate>
                <div class="progress">
                    <asp:Image ID="ImgProgress1" runat="server" ImageUrl="~/images/ajax-loader-arrows.gif" ToolTip="loading..." />&nbsp;please wait...
                </div>
                </ProgressTemplate>
             </asp:UpdateProgress>     
             <asp:FormView ID="FormView1"  runat="server" DefaultMode="ReadOnly"  >
                 <ItemTemplate></ItemTemplate>
                 <EditItemTemplate></EditItemTemplate>
                 <InsertItemTemplate></InsertItemTemplate>
                 <EmptyDataTemplate>
                 </EmptyDataTemplate>
                 <PagerTemplate >
                 </PagerTemplate>
            </asp:FormView>
         </asp:panel>
      </contenttemplate>
    </asp:UpdatePanel> 
    
    <asp:UpdatePanel ID="UpdContent" runat="server" UpdateMode="conditional" ChildrenAsTriggers="false"  >
      <ContentTemplate>
         <asp:Panel ID="PnlMain" runat="server">
            <asp:UpdateProgress ID="UpdateProgress2" DynamicLayout="true" runat="server" AssociatedUpdatePanelID="UpdContent" DisplayAfter="0" >
                <ProgressTemplate>
                <div class="progress">
                    <asp:Image ID="ImgProgress1" runat="server" ImageUrl="~/images/ajax-loader-arrows.gif" ToolTip="loading..." />&nbsp;please wait...
                </div>
                </ProgressTemplate>
             </asp:UpdateProgress>
    
             Content
    
       </asp:Panel>
     </ContentTemplate> 
       <Triggers ></Triggers>
    </asp:UpdatePanel> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple page with my ScriptManager and my UpdatePanel , and my
I have Update panel in Master page: <asp:ScriptManager id=CartScript runat=server></asp:ScriptManager> <asp:UpdatePanel id=CartBox runat=server updateMode=Conditional>
Here's the problem: 1.) We have page here... www.blah.com/mypage.html 2.) That page requests a
I have a page that is generated which inserts an HTML comment near the
On my Page_Load command for a page, I have a couple of tests that
I have an ASP.NET page which has a script manager on it. <form id=form1
I have a page where there is a column and a content div, somewhat
I have a page using <ul> lists for navigation (Javascript changes the styling to
I have a page with many forms in panels and usercontrols, and a requiredfield
I have a page upon which a user can choose up to many different

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.