Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

ASP.NET 2.0 Web Part Infrastructure and SharePoint 2007 : Page 4

Find out how to make your Web Parts communicate with each other and share data.


advertisement
SharePoint 2007 Built on ASP.NET 2.0
Did I mention that SharePoint 2007 is built on ASP.NET 2.0? Yes it's true; a SharePoint 2007 Web application is nothing but an ASP.NET 2.0 Web application running on a port. This includes SharePoint Central Web Administration (SCAW). More than the Web application itself, the deep-down connection between ASP.NET 2.0 and SharePoint 2007 is visible at many places. And when I say SharePoint 2007, I am using this as a catch-all phrase to refer to both WSS 2007 and MOSS 2007. Here are a few examples of where you see ASP.NET 2.0 in SharePoint 2007.
  • A SharePoint ASPX—A SharePoint ASPX is a combination of an "aspx" file and a back-end DLL. The back-end DLL for most ASPX pages is available precompiled under the Microsoft.SharePoint.ApplicationPages namespace. There is a complicated inheritance structure available within various SharePoint pages, but eventually they all end up inheriting from System.Web.UI.Page. So they are all ASP.NET 2.0 Web pages.
  • A SharePoint WebControl—SharePoint comes with a number of WebControls. These are not Web Parts mind you—just WebControls, which inherit from System.Web.UI.Control.
  • A SharePoint Web Part—A SharePoint Web Part inherits from an ASP.NET 2.0 Web Part. There is also support built in for supporting SharePoint 2003 Web Parts. Because Web Parts are the focus of my article, I will elaborate more on this shortly.
  • A SharePoint WebPartManager—A SharePoint WebPartManager is a sealed class that inherits from System.Web.UI.WebControls. WebPartManager, which is the ASP.NET 2.0 WebPartManager.
  • MasterPage based Customization—Customizing SharePoint 2003 was so difficult that I like to say that SharePoint 2003 was barely customizable. This picture is changing with SharePoint 2007, thanks to ASP.NET 2.0 Master Pages. Not only that, if you customize a SharePoint 2007 ASPX, you are "customizing" a page, which stores the differences you create in the database. When a Web request comes in, SharePoint 2007 takes the differences in the database, adds them to the file stored on the disk, and then presents ASP.NET 2.0 with the final customized page. This means ASP.NET 2.0 never knew whether the page was customized; to ASP.NET 2.0, it is just another page. In addition to better manageability, the biggest plus side of this is minimal performance hit due to customization.
The list goes on. There are many other places where you can see ASP.NET 2.0 running behind the scenes in SharePoint 2007, such as membership provider-based authentication, site-map provider, URL rewriting, and pretty much any other ASP.NET 2.0 concept you can think of.

I suggest that you dig into the DLLs of SharePoint using a tool such as Reflector. You will note that SharePoint 2007 uses many concepts from ASP.NET 2.0. But for now, I am going to refocus on Web Parts and make the discussion specific to Web Parts in SharePoint 2007. Web Parts in SharePoint 2007
So far, I've covered the most essential basics of the ASP.NET 2.0 Web Part framework. Now I'll take this discussion to Web Parts in SharePoint 2007.

If you dig deeper into the libraries that come with SharePoint 2007, you'll find a class called Microsoft.Sharepoint.WebpartPages.WebPart that inherits from System.Web.UI.WebParts.WebPart. Now why are there two base classes for Web Parts, and which one should I use when writing Web Parts for SharePoint 2007? The answer lies in "backward compatibility." There is a huge installed base for SharePoint 2003 and a number of Web Parts written for SharePoint 2003. These Web Parts are rebased from the Microsoft.Sharepoint.WebPartPages.WebPart class for support purposes. This turns them into ASP.NET 2.0 Web Parts and yet offers the backward compatibility they need.



However, for most scenarios I strongly recommend that you simply inherit from the ASP.NET 2.0 Web Part class instead. The Microsoft.SharePoint.WebPartPages.WebPart class exists only for backward compatibility with SharePoint 2003. In specific cases, you may want to use the SharePoint Web Part when you need cross-page connections, connections between Web Parts that are outside of a WebPartZone, a client-side connection, or the data-caching infrastructure. However, for the most part you should use ASP.NET 2.0 Web Parts instead. The one notable exception is that GenericWebPart-based user controls won't work in SharePoint. This "tie down" is due to security restrictions, but should you choose to use user controls in SharePoint, you could easily write the equivalent of GenericWebPart yourself.

In this article, I have written two ASP.NET 2.0 Web Parts, so they should be usable directly within SharePoint 2007. The obvious question is: What do I need to do to use those Web Parts in SharePoint 2007?



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap