Hello,

My problem is :

I have a .aspx page where I use a ScriptManager and a UpdatePanel.

In the update panel I generate controls based on user interactions.
My problem is this : when I add dynamically the CustomControl (.ascx page ) in the UpdatePanel ( the CustomControl has a ScriptManagerProxy ) the AsynchronousPostBack for the .ascx page doesn't work, at all.

The fact that this is the first time I try this is not a bonus :D .

code for adding the user controls :

Control myControl = Page.LoadControl("NewUser.ascx");
            myControl.ID = "NewUser";
            placeHolder.Controls.Clear();
            placeHolder.Controls.Add(myControl);

placeHolder is in the UpdatePanel.

and all the Ajax calls inside the CustomControl are in the UpdatePanel of the CustomControls like this :

<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
</asp:ScriptManagerProxy>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
     <asp:TextBox runat="server" ID="txt_Username" OnTextChanged="txt_Username_TextChanged" />
                  
    </ContentTemplate>
</asp:UpdatePanel>

So I see the dynamically added CustomControl in the page but the AsynchronousPostBack is not called for the CustomControl , any ideas ? Help ? :)

Dani AI

Generated

Most likely causes and a short checklist for this scenario (dynamic ASCX inside an UpdatePanel that contains a ScriptManagerProxy):

  • ScriptManager vs ScriptManagerProxy: a ScriptManagerProxy does not replace a real ScriptManager. The hosting page (or master page) must contain exactly one ScriptManager. If the page lacks one, the proxy inside the user control will not enable AJAX behavior. See the official docs for details: ScriptManagerProxy Class.

  • Dynamic controls and the page lifecycle: controls added dynamically must be recreated on every postback before viewstate and postback data are processed (OnInit/LoadViewState time). If the control is added too late (for example only in response to a button click during Page_Load and not recreated on the next postback), server events like TextChanged will not fire.

  • Common things to verify:

    • Ensure the hosting page has a single ScriptManager (move it to the master page if appropriate).
    • Persist whatever flag identifies the dynamic control (ViewState, hidden field, session) and re-create the control in OnInit so events and viewstate get restored.
    • Ensure input controls that should trigger postbacks have AutoPostBack=true, or register them as async triggers for an UpdatePanel.
    • Avoid adding/removing the control only during the same postback that raises the event; recreate it on subsequent postbacks.
    • Check browser console for JS errors and the Network tab for the XHR request that UpdatePanel generates—AJAX will fail silently if a script error occurs.
  • Debugging tips:

    • Temporarily enable tracing and check lifecycle timing.
    • Set stable IDs on dynamic controls so viewstate mapping is consistent.
    • If you must register client scripts from the ASCX, prefer ScriptManager APIs (or the proxy when a ScriptManager exists) rather than embedding another ScriptManager.

As suggested, there is nothing inherently broken about using UpdatePanel + user control + ScriptManagerProxy. If these checks do not fix it, post the minimal complete code (page markup + code-behind) so the exact lifecycle and recreation logic can be reviewed.

Recommended Answers

All 3 Replies

no one ? :)

miculnegru>no one ?

Yes, There is no problem with ScriptManager, UpdatePanel, UserControl, and ScriptManagerProxy.

If your code doesnot function then post the complete code.

what are you tring to achive here?
try to be more specific and maybe as adatapost said try to put your code in here

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.