Usercontrol postback not working in updatepanel
I have a home page with an update panel:
<asp:UpdatePanel ID="UpdatePanel" runat="server" ChildrenAsTriggers="true" EnableViewState="False"
UpdateMode="Conditional">
<ContentTemplate>
<div id="mainContent">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</ContentTemplate>
<Triggers>
</Triggers>
</asp:UpdatePanel>
Then I have a Default.aspx page that uses the main page file:
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<asp:PlaceHolder ID="plhCurrentItem" runat="server"></asp:PlaceHolder>
</asp:Content>
I am loading usercontrols programmatically into placeholder with id plhCurrentItem.
The problem is when I click the button in the usercontrol, no event is fired. The user control simply disappears and the updated panel remains blank.
What am I doing wrong?
Update
Code used to add usercontrols. The LoadControls method is called from the Page_load event.
Control ctlCurrentItem = null;
public string currentControl
{
get { return ((string)Session["currentControl"]); }
set { Session["currentControl"] = value; }
}
public void LoadControls()
{
switch (currentControl)
{
case "Home":
ctlCurrentItem = Page.LoadControl("~/pages/Home.ascx");
ctlCurrentItem.ID = "Home";
break;
case "Resume":
ctlCurrentItem = Page.LoadControl("~/pages/Resume.ascx");
ctlCurrentItem.ID = "Resume";
break;
case "Projects":
ctlCurrentItem = Page.LoadControl("~/pages/Projects.ascx");
ctlCurrentItem.ID = "Projects";
break;
case "Contact":
ctlCurrentItem = Page.LoadControl("~/pages/Contact.ascx");
ctlCurrentItem.ID = "Contact";
break;
default:
return;
}
plhCurrentItem.Controls.Clear();
plhCurrentItem.Controls.Add(ctlCurrentItem);
}
+2
source to share
1 answer
Place a call to LoadControls on OnPreInt from a page resource by loop :
Use this event for the following:
- Check the IsPostBack property to determine if this will be the first time the page is rendered.
- Create or re-create dynamic controls.
- Dynamic setting of the main page.
- Set the Theme property dynamically.
- Reading or setting values ββfor profile properties.
+2
source to share