Why Does Asp.Net UserControl Get An "F" With ViewState?

171 Views Asked by At

I've never had much of a need for UserControls until recently. The reason is too lengthy and out of scope for this thread.

I will say that the UserControls have to be loaded dynamically. The variable in which to load the UserControls is stored in a custom server control's property, which of course resides in ViewState.

My problem, as many others developers have expressed, is that the UserControl will not retain ViewState! All the best opinions say to load the UserContol during the Init stage of the Page life cycle. But if I load the UserControl from CustomServerControl's ViewState, I cannot do this in the Init phase, because ViewState has not been initialized.

What is driving me crazy is that the Asp Framwork will route events (Button clicks etc.) to a UserControl but it is not smart enough to load the ViewState.

Maybe this is simply a rant, but I wish I could find an answer for this simple question:

"Why can't a UserControl retain ViewState LIKE ANY OTHER WebControl when loading is required in the Page_Load phase?"

0

There are 0 best solutions below