We've updated our theme! Please refresh your browser if things don't look right.
vote up 3 vote down
star
2

This is an almost religious question; what are your preferred base class for building WebParts in SharePoint? Are you using the ASP.NET WebPart (System.Web.dll) or the SharePoint WebPart (Microsoft.SharePoint.dll)?

What are the pros and cons of respective choice?

I personally like to use the ASP.NET WebPart class!

/WW

flag
In SharePoint 2010 the Visual Web Parts are based on the ASP.NET WebParts as well as most of the new built-in web parts in SharePoint 2010. Also for sandboxed webparts you have to go with the ASP.NET Web Part. – Wictor Oct 27 at 7:27

7 Answers

vote up 4 vote down

Like Bill mentions, the SharePoint web part is primarily there for backwards compatibility, although it does provide 4 features that are not available in the standard asp.net web part:-

  • Cross page connections
  • Connections between Web Parts that are outside of a zone
  • Client-side connections (Web Part Page Services Component)
  • Data caching infrastructure, including the ability to cache to the database

This information comes from the remarks on the SharePoint web part MSDN page...

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.webpart.aspx

Hope this helps :-)

link|flag
Thanks Russel, I'm aware of these features, and I have not had any cases when those scenarios fitted and you can work around most of them quite easily using the .NET framework built-ins and client side scripting. – Wictor Oct 27 at 7:24
Yep, me too. I've never found the need to use the SharePoint web part, I've always used the Asp.Net one. :-) – Russell Giddings Oct 27 at 12:12
vote up 2 vote down

SharePoint web parts are there for backwards compatibility. For new development we should use the ASP.NET web parts.

link|flag
I can agree on that and SP2010 will probably tell us more about that. But I doubt MS will stop supporting the SP WebParts... – Wictor Oct 8 at 17:57
1 
Agreed. But the future investment won't be in the "old" SharePoint web parts. – Bill Oct 9 at 10:45
vote up 2 vote down

when it comes to SP2010, webparts that derive from the SharePoint web part are not supported in Sandbox solutions.

Source: An Overview of the SharePoint 2010 Sandbox Solution

link|flag
1 
Yup, I've seen that. And also the Visual Web Part derives from the ASP.NET webpart. So my recommendation stands still; use the ASP.NET Web Part when creating web parts. – Wictor Nov 13 at 11:48
vote up 1 vote down

I use the ASP.NET class as that's what Microsoft recommends in Working with ASP.NET 2.0 Web Parts and Windows SharePoint Services 3.0.

I haven't found or seen any good reasons to use one over the other apart from the different feature sets each class offers. That is, advanced web part connections are only offered by the SharePoint web part class.

Perhaps MS hoped the generic ASP.NET web part class would be used more outside of SharePoint?

link|flag
Both versions supports WebPart connections, though in different ways. For example SharePoint webparts can have cross-page-connectons. – Wictor Oct 7 at 13:18
Oops - forgot that detail, fixing answer! – Alex Angas Oct 7 at 13:33
NP :-). As I see it that is one of the few scenarios where you should use the SharePoint WebPart...and seriously how often do you use cross-page connections? I've never created a solution when that was necessary. – Wictor Oct 7 at 13:36
vote up 1 vote down

There's a few extra reasons for using the ASP.Net WebPart over the SharePoint WebPart.

Basically, the ASP.Net WebPart can be used IF your solution/client/project ever had to shed the MOSS Skin and the decision was made to move from MOSS onto another platform.

link|flag
Agreed, this is the most common answer, but this argument is often killed with the statement that as soon as you add a reference to the SharePoint dlls you could have used the SP version anyways... – Wictor Oct 9 at 1:30
vote up 0 vote down

There is one thing I like about Microsoft WebParts: caching using SharePoint and that is not available on ASP.NET WebParts.

link|flag
1 
Yes, that's true. While using ASP.NET WebParts you can use the OOB ASP.NET caching techniques – Wictor Oct 7 at 17:10
vote up 0 vote down

I haven't find a good reason not to use sharepoint webpart.

If my sharepoint project is gonna be on asp.net w/o Sharepoint chances are you'll have to rewrite the entire application either way. ...

It's more likely youll use connections between multiple zones. That actually won't depend on the infrastructure, but on the user dragging the webParts, so I'd go with Sharepoint webparts just because it doesn't have restrictions on WSS.

Regards,

Nicolas.

link|flag
ASP.net webparts handle connections between zones, so that's no restriction. – Wictor Oct 29 at 7:01
Right Wictor. I misunderstood Russell's answer. However, I cannot find a reason why not using Sharepoint's Base Webpart class. – Nicolas De Irisarri Oct 29 at 14:58

Your Answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.