Reputation: 5802
I am using UpdatePanel and loading dynamically the content:
<asp:UpdatePanel runat="server" ID="updatePanel" UpdateMode="Conditional">
<ContentTemplate>
<div id="dashboard-main">
<div id="dashboard-content">
<div class="d-content">
<asp:PlaceHolder runat="server" ID="ContentPanel">
</asp:PlaceHolder>
</div>
</div>
<div id="sub-content">
<ul id="nav-02">
<li class="current">
<asp:LinkButton CommandArgument="Stuff" OnClick="LoadMiniDash" runat="server" ID="myStuff">
My Stuff</asp:LinkButton></li>....
What I do is once the LinkButton is pressed, I load a control to the ContentTemplate:
protected void LoadMiniDash(object sender, EventArgs e)
{
string miniDashName = ((LinkButton)sender).CommandArgument;
Control control = Page.LoadControl("~/controls/Dashboard" + miniDashName + ".ascx");
ContentPanel.Controls.Clear();
ContentPanel.Controls.Add(control);
updatePanel.Update();
}
My problem is, that inside this newly loaded control, there is another Button. once clicked, the updatepanel gets emptied and not postback to the control is made. (it does however do a post to the page itself async. but i see the control won't reach its own code once clicked).
what can be the problem?
thanks
Upvotes: 0
Views: 3160
Reputation: 8359
I just tried to rewrite your question. When you load your userControl it appears in the updatePanel. When you hit the button in the userControl, your updatePanel gets updated - and your userControl "disappears".
Imo it disappears because you do not reload your userControl. I tried the following snippet:
protected void btnLoadControl_Click(object sender, EventArgs e)
{
/// save the name of the userControl to load in a SessionVar
Session["userControl2Load"] = "ucDemo.ascx";
Control control = LoadControl("ucDemo.ascx");
phDemo.Controls.Clear();
phDemo.Controls.Add(control);
upDemo.Update();
}
/// reload your userControl on every init of the updatePanel
/// when the sessionVar is set
protected void upDemo_Init(object sender, EventArgs e)
{
if (Session["userControl2Load"] != null)
{
string controlName = Session["userControl2Load"].ToString();
Control control = LoadControl(controlName);
phDemo.Controls.Clear();
phDemo.Controls.Add(control);
}
Debug.WriteLine("upDemo Init");
}
it worked for me. Let me know if it work for you too. hth
Upvotes: 1
Reputation: 839
I have faced similar issue.. and you know solution to this problem is very simple..
Logic is .. If you have one or more update panel in the same page then properties of all update panel should be same such as
Update Mode : Always
EnableViewState : true(if you are using it)
For example you have 3 update panel in the same asp.net ajax page with following id
UpdatePanel1
UpdatePanel2
UpdatePanel3
In the Update Panel 1 (UpdatePanel1) you have a button which specific a record from the gridview. On the click on the button in the update panel1, FormView in the UpdatePanel2 should display the corresponding values.
To achieve this, you need to specific Update Panel Properties of (UpdatePanel1, UpdatePanel2) as
ChildrenAsTrigger : True
EnableViewState : true
RenderMode : Block/Inline
UpdateMode : Always
Visible : true
Doing above activity values in the UpdatePanel3 is changed or you can say it's not depending on the UpdatePanel1 or UpdatePanel2
If you find it useful, please mark it as your answer else let me know...
Upvotes: 0