Groups | Blog | Home
all groups > asp.net building controls > september 2007 >

asp.net building controls : Proper way to reload CompositeControl when its state must change after Postback


jeljeljel
9/19/2007 3:40:34 PM
I am creating a CompositeControl that contains a Table. The rows in
the Table are controlled by an internal pager. The control renders
the pager and the table. When the user clicks the pager, the control
shows the next set of records in the table.

Assume after the OnLoad method the control has regenerated to the
exact state when the last time the page unloaded (with ViewState or
some other means -- important part is the control's state is the same
as when the page unloaded). Then the control changed events fire,
then the post back events fire. A post back event is received from
the Pager that the user requested a new page.

So now the CompositeControl must "tear down" the old markup and
regenerate the new markup.

Is this as simple as calling Controls.Clear()? There must be more to
it, b/c when I call Controls.Clear(), the Count becomes 0, and I
create the new markup (in CreateChildControls). The Count property on
Controls.Count shows new controls have been added, but when the page
renders, the original markup is what displays.

Thanks,
John
Teemu Keiski
9/20/2007 10:36:43 PM
Hi,

do you mean

1. call Controls.Clear()
2. Set ChildControlsCreated flag to false
3. call EnsureChildControls()

Note: putting call of Controls.Clear() as first line in CreateChildControls
removes the first step.

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net


[quoted text, click to view]

AddThis Social Bookmark Button