Code Project

Link Unit

Friday, September 04, 2009

Design decision to use ascx control in sharepoint webpart versus pure sharepoint webpart


1. Create asp.net webusercontrol (.ascx), and then load that user control in the newly created webpart.

2. Create a webpart from scratch, by putting the code to generate each and every control in code.

if you need to create a control with a really advanced user interface, for example many controls and stuff, then a user control could be much easier to create.

I have found that the execution lifecycle (control viewstate, event bubbling, etc.) is a pain when going with Option 2. I choose Option 1 because the viewstate is easily managed in the code. Additionally, I like Option 1 because I can visually design the page using the VS toolbox to drag and drop controls on the design surface as opposed to Option 2 where you have to handle each control manually in code.

The approach 2 may sound difficult because of not very great integration with Galleries , but if you have the luxury of invest the time, you'll be better off in the long run.

No comments: