Friday, May 30, 2008

Create and Deploy a Web Part

Web Parts


Webparts enables the developers to create web pages that the end user can modify in the browser.


Three main components on webpart pages are:



  1. WebPartManager : - A web part manager is responsible for adding and maintaining the instances of the Webparts in the webpartzones.

  2. WebPartZone : - Webpartzones are place holders for Webparts. These are used to group the Webparts and create different sections in a webpage.

  3. WebParts : - These are the actual controls that are added to the Zones.


    Create a custom webpart

    1. Create a class library and inherit from System.Web.UI.Webcontrols.Webparts.webpart class
    2. Overide the functions like CreateChildControls, RenderControl, RenderContent etc.
    3. Create properties and give attributes like personalizeble, webbrowsable etc as needed.
    4. Add the following property in the Assembly.info file to deploy your Web Part assembly with a strong name to the bin directory : [assembly: AllowPartiallyTrustedCallers()]
    5. Compile the file and give a strong name (if required).
    6. Copy the dll to either bin directory of the webapplication or the GAC.
    7. Register the dll as a SafeControl in the web.config of the web application.
    8. Go to SiteSettings à Web Part Galleries and click on new.
    9. Select our webpart and click “Populate Gallery”.

Now its ready to be used in the web pages.


Thanks and Regards,


Sarath Raj.