I have an .aspx page that dynamically creates multiple user controls, each of which have their own code behind which fires based on several events at the user control level. The problem is, before the events fire in a particular user control, the parent page Load
method fires as well. Because each of the controls are added dynamically, this isn't a trivial amount of processing since each control must be re-added.
I'd like to be able to fire UserControl events without forcing an update on the page that hosts it. I've tried putting the entire user control in an UpdatePanel
, but postbacks within the user control still force a page load for the parent.
Here's some test code with certain parts omitted and the control added declaratively, instead of programmatically.
.ASPX Parent Page
<!-- language: lang-html --><%@ Page Language="vb" CodeBehind="MyParent.aspx.vb" %>
<%@ Register TagPrefix="uc" TagName="Control" Src="MyControl.ascx" %>
<form id="form1" runat="server">
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<uc:Control ID="Control1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
.ASCX User Control
<!-- language: lang-html --><%@ Control Language="vb" CodeBehind="MyControl.ascx.vb" %>
<p>Control Added</p>
<asp:Button runat="server" Text="ForcePostBack"/>