Custom Composite Control, child User-controls loosing view state

M

Mike J.

I've created composite custom control which dynamically creates and arranges
it's child controls based on some xml data. Beside the simple web form
controls there is an option of loading user-controls (UC) at run-time. Child
controls are created/loaded/initialized in overridden CreateChildControls
and then arranged in pages. Meaning - put in separate HtmlTables with only
active one visible (property HtmlTable.Visible =
is_this_page_the_active_one() set just before rendering).

Now, everything works fine except the UC(s). UCs are loaded and displayed
as they should be, their child-controls are "responsive" to the events, data
entered is preserved across postbacks etc.

Only after user switches to another page (UCs parent HtmlTable.Visible =
false), and then switches back to the previous one is when UC and it's child
controls loose their view state. All other "regular" controls preserve view
states across page switching.

This left me completely confused. UCs are loaded at exact time when all the
other controls are created. They clearly preserve their view state across
the postback. I made sure (through the debugger) that UCs view state is
restored after switching to another page. It only gets lost after the switch
back. There is no special initialization of UC's child controls.

I've been struggling with this for days. Can someone please shed some light
on this problem for me?
 
J

John Saunders

Mike J. said:
I've created composite custom control which dynamically creates and arranges
it's child controls based on some xml data. Beside the simple web form
controls there is an option of loading user-controls (UC) at run-time. Child
controls are created/loaded/initialized in overridden CreateChildControls
and then arranged in pages. Meaning - put in separate HtmlTables with only
active one visible (property HtmlTable.Visible =
is_this_page_the_active_one() set just before rendering).

Now, everything works fine except the UC(s). UCs are loaded and displayed
as they should be, their child-controls are "responsive" to the events, data
entered is preserved across postbacks etc.

Only after user switches to another page (UCs parent HtmlTable.Visible =
false), and then switches back to the previous one is when UC and it's child
controls loose their view state. All other "regular" controls preserve view
states across page switching.

This left me completely confused. UCs are loaded at exact time when all the
other controls are created. They clearly preserve their view state across
the postback. I made sure (through the debugger) that UCs view state is
restored after switching to another page. It only gets lost after the switch
back. There is no special initialization of UC's child controls.

I've been struggling with this for days. Can someone please shed some light
on this problem for me?


I suggest you don't use .Visible. .Visible determines whether the control
renders at all, not whether it is visible or not.

Instead, use:

table.Style["display"] = "none";
 

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,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top