0

I have UpdatePanel with button.

<asp:UpdatePanel runat="server" ID="upOuter" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Button ID="btnNestInnerPanel" runat="server" 
        OnClick="btnNestInnerPanelClick" Text="Nest Update Panel" />
    </ContentTemplate>
</asp:UpdatePanel>

I want to nest inner updatepanel with other button in outer updatepanel by click that button. And I want to update inner updatepanel by click new button. Page has such behind code:

public partial class _Default : Page
{
    private Button btnInner;

    protected void Page_Load(object sender, EventArgs e)
    {
        btnInner = new Button { Text = "Click Me", ID = "MyId" };
        btnInner.Click += btnInnerClick;
    }

    protected void btnNestInnerPanelClick(object sender, EventArgs e)
    {
        UpdatePanel upInner = new UpdatePanel();
        upInner.UpdateMode = UpdatePanelUpdateMode.Conditional;
        upInner.ContentTemplateContainer.Controls.Add(btnInner);
        upOuter.ChildrenAsTriggers = false;
        upOuter.ContentTemplateContainer.Controls.Add(upInner);
    }

    private void btnInnerClick(object sender, EventArgs e)
    {
        Button btn = (Button)sender; 
    }
}

When I click first button, it causes update of panel and inner panel appears. That's correct. But if I click newly created button in inner panel, btnInnerClick handler is not raised. Does anybody know what's problem?

If I nest dynamically inner updatepanel in simple placeholder (not in outer updatepanel), btnInnerClick handler is raised correctly. I have no idea...

1
  • all ASP.Net dynamic controls must be re-created on page load in order to properly have their events called. Google: ASP.Net Page Lifecycle and Dynamic Controls... Commented May 7, 2014 at 14:22

1 Answer 1

0

all ASP.Net dynamic controls must be re-created on page load in order to properly have their events called. Google: ASP.Net Page Lifecycle and Dynamic Controls...

https://web.archive.org/web/20210330142645/http://www.4guysfromrolla.com/articles/092904-1.aspx

Sign up to request clarification or add additional context in comments.

1 Comment

Oh, thanks. You are right. I replaced creation of inner updatepanel in Page_Load. So, event of its button handled correctly. But I want to create inner update panel with button by click only. There is problem with partial postbacks. I've found solution here stackoverflow.com/questions/213429/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.