January 16, 2010

ASP.NET Dynamic User controls

Today after long time...I moved to an assignment to work in ASP.NET after the gap of almost nealry 5 years. I started working on an Intranet Portal for a financial institution.

We wanted to generate certain UIs dynamically, we chose different user controls will be loaded based on the user requirement. One thing I learned today is "Dynamic Controls Should be Loaded on Each PostBack" On every postback literally you need to load the controls again and again. If you want the control to have its Viewstate data preserved, adding the USercontrols to page (Parent) should happen before LoadViewstate event gets fired in the page life cycle.

Normally the user controls will be added as Controls.Add(UsercontrolPath), where ocntrols is Place holder in the page/another user control.

I will write more about this assignement that looks very interesting.