Archive for May, 2010

Recently, I came across a problem where I had to dynamically add a hidden user control into the ContentTemplate of an ASP.NET AJAX accordion control.  This, was over complicated, by the fact that this accordion was nested in a tab control and getting some data synchronously and some asynchronously. 

One of the problems I faced was the usual control manipulation in the Page_Load event! By this I mean checking to see if the Page.IsPostBack to ensure your not loading the controls again.

This particular problem related to drop down lists. 

After several unsuccessful attempts to get the logic just right, I decided to revisit the ASP.NET Page Life Cycle to refresh my memory as to what was going on.

As its been a while since I’d came across this situation, I had forgotten all about Page_Init, which happens before the View State is loaded.

So, by loading all the dropdowns in Page_Init i was able to retrieve the correct values every time in the Event handler of the button click which caused the post back.

I know this means the dropdowns are loaded on postback too, but I feel this method is far easier and cleaner than checking the Page.IsPostBack property in the Page_Load event.