Event Fires after CreateChildControls

J

John Bankhead

I have created a C# control that creates its objects within
CreateChildControls. One of those objects is a button which I have attached
to a command event. The command event fires after CreateChildControls runs,
but I want the clicking of the button to have an effect on what items
CreateChildControls creates. Is this possible? Obviously I can make this
happen by setting a value on an object on the client side and reading it in
CreateChildControls. But still, I am curious.
 
T

Teemu Keiski

Hi,

you could do this in Click event handler (of the Button) or have customized
routine to do it (assuming we are inside the custom control logic all the
time)

a) Clear child controls collection by calling Controls.Clear() and clear
child state by calling ClearChildViewState()
b) set ChildControlsCreated to false
c) Do the stuff that has impact on child control creation
d) finally call EnsureChildControls which willl call CreateChildControls (it
does that when ChildControlCreated flag is false)

So simply saying, you recreate the control in such scenario.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top