Ben Collins
Ben Collins

Reputation: 20686

Updating a dynamic control

I've got a custom web part with Accordion panes from the AJAX Control Toolkit as children that are used to render a site map hierarchy. Each pane includes a div with text input and 3 LinkButtons used to edit the sitemap data: "Add Child", "Update", and "Delete".

Currently, all these controls are created in the overridden CreateChildControls method.

When the "Add Child" LinkButton is clicked, the event handler is fired, and a new node is added to the sitemap. When the postback completes, the control should re-render with the new, empty node in the hierarchy, but it doesn't. After a new GET request, the new node appears. After reading for a while, I thought my problem was that I was creating my child controls too early in the process because CreateChildControls is called before Control events are fired, so I moved that bit to the OnPreRender method. But now the Control events don't fire because I'm hooking them up too late in the Page lifecycle (see here: Custom Control Events Not Firing).

My question is this: how do I ensure that the custom control renders the results of its child control event handlers?

As an aside, does it matter that I'm doing this in a web part rather than a custom server control (e.g., is the lifecycle different)?

Upvotes: 2

Views: 171

Answers (1)

brumScouse
brumScouse

Reputation: 3216

You could call EnsureChildControls in OnInit of the page. This will ensure that child controls will be recreated before any events are handled.

Upvotes: 1

Related Questions