Dynamically load specific User Control from postback
I have a menu on a .aspx page, which will load a specific user control depending on which menu option is clicked. This part is working fine.
The problem I'm running into is when I instantiate a post back from the dynamically loaded user control, the .aspx page is reloaded. Now after researching a few of the other questions on here, I gathered that I have to recreate the User Control each time the post back is instantiated. However, the question I have might be quite simple, but how do I reload the specific User Control (and fire an event such开发者_如何学JAVA as OnClick) based on what is posted back to the server?
So my question is: What exactly gets passed back to the server on post back, and is there something in the post back request that will allow me to load the specific control? If there is, how would I get to it?
To do it the manual way, you would have to recreate the control(s) before ViewState is reloaded, like during OnInit
for example.
There is a control called the DynamicControlsPlaceHolder
that takes care of persisting dynamic controls for you. It's a definite time saver, and it makes persisting dynamic content easy.
Here is a link to the control:
http://www.denisbauer.com/ASPNETControls/DynamicControlsPlaceholder.aspx
To better understand what postbacks do, you need to understand the ASP.NET page lifecycle. Here is an MSDN article that explains it in detail:
http://msdn.microsoft.com/en-us/library/ms178472.aspx
精彩评论