ASP.Net WebPart or SharePoint WebPart

Wictor Wilen MCA MCM MVP
  • ASP.Net WebPart or SharePoint WebPart Wictor Wilen MCA MCM MVP

    This is an almost religious question; what are your preferred base classes 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 each respective choice?

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


  • 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?

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

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

  • 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 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...

    Hope this helps :-)

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

    If my sharepoint project is gonna be on 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.



  • 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

  • I'm a bit torn between the two actually, and my reasons are for things that don't often get a mention.

    I'm a fan of the ASP.NET web parts .dwp/.webpart xml file schema. I think it's a lot cleaner and you don't have to specify a namespace whenever you specify a custom property value in the file.

    However some of the things that (sometimes) make me revert back to the SharePoint WebPart are

    1. GetToolParts() is better than CreateEditorParts()

    With GetToolParts(), we could control the standard web part properties, and hide some if we wanted to. I haven't worked out how/if you can do this with ASP.NET WebParts. For example:-

        public override ToolPart[] GetToolParts()
            ToolPart[] parts = new ToolPart[1];
            WebPartToolPart wptp = new WebPartToolPart();
            //prevent detail link and title from being changed
            parts[0] = wptp;
            return parts;
    1. SharePoint's WebPart.Qualifier was a handy little int value that you could use when you wanted to deal with multiple instances of a web part on a page. Easy to work around, but still handy!

    2. SharePoint's WebPart.ClassResourcePath was good in order to isolate your resources (images, css etc) into their own location and then easily refer to that location from within the web part.

Tags web-part development
Related questions and answers
  • How can I get the selected language in the screenshot, from inside of a webpart? alt text I'm using SharePoint 2010. My webpart is a "visual web part" created in VS2010. I'm trying things like SPContext.Current.Web.CurrentUser.RegionalSettings and SPContext.Current.Web.Language" but ofcourse these things have nothing to do with that setting. :-| Can someone please help me? What property am I looking for.

  • I'm developing a webpart for SharePoint 2007 and have seen several posts that advise to do all the creation of controls in the code-behind. I'm transitioning from Java J2EE development so I don't have the platform history of .Net/ASP/etc. In other places it shows how you can do the same thing by embedding the control definition into the asp page with tags My question is this: What is the rule governing where to implement controls? Has this rule changed recently, ASP vs ASP.Net or ASP.Net MVC maybe? Is this advice limited to SharePoint development?

  • I am using SharePoint Server 2007 Enterprise with Windows Server 2008 Enterprise. I am developing using VSTS 2008 + C# + .Net 3.5 + ASP.Net. I want to develop a WebPart, like a tab based control, like task manager, items (e.g. processes, users, etc.) are managed by tab on the top for different categories, and in each category tab, items are organized in list. I need to get information about which tab is selected in my requirement. Any reference code or document?

  • Audience of the webpart to 'Staff'. The idea is that anonymous viewers can't see the web part, but logged-in members of staff can see the webpart. This works fine, as long as I am browsing the site from the server on which SharePoint is running, using the internal domain name (e.g. http://localhost:5050/site). If I view the site home page while not logged in, I can't see the webpart -- this is the correct behaviour. However, if I view the site via the public address (e.g. while not logged in, I can see the webpart. (I shouldn't be able

  • I am using SharePoint Server 2007 Enterprise with Windows Server 2008 Enterprise. And I am developing using VSTS 2008 + C# + .Net 3.5 + ASP.Net + JavaScript (jQuery). I met with the following security warning in browser (at the top of the page in IE) when browse a page -- "An add-on for this web site failed to run. Check the security settings in Internet Options for potential conflicts.../css files in head section. I am developing a webpart which such script files will impact (i.e. my webpart will generate a div called "tabs" which such below scripts will impact). Any security issues

  • Possible Duplicate: How to use JavaScript and CSS in a web part? I am using SharePoint Server 2007 Enterprise with Windows Server 2008 Enterprise. I am developing using VSTS 2008 + C# + .Net 3.5 + ASP.Net. I have the following code which works correctly in ASP.Net (aspx) and I want to implement the same function in a WebPart and deploy into a page of SharePoint publishing portal site. Any ideas how to implement? My major confusion is how to deal with the code in the head part of the following code? Any reference code or document? Here is the aspx code I am using, <!doctype

  • I have a webpart that is part of a larger solution, deployed as a WSP using WSPBuilder. I can see the SafeControl entry in the web.config and can see that the assembly has deployed to the GAC. The solution reports as installed OK in Central Admin and the feature is activated at the site collection. When I attempt to add the webpart to a page, I'm getting an error stating that the "Type could not be found or is not registered as safe." I have removed this solution from MOSS and completely re-created the webpart, in case I've messed up GUIDs or something. I'm not sure what to check next. Any

  • applications inside Sharepoint), but I wouldn't want to do it that way even though it would be much easier for me to develop such applications, because I'm primarily hardcore MVC developer... on the BCS level within Sharepoint then, but I'd still need my rich custom controls, that would display data in unusual ways. What about sandboxed solutions? Is this something I should use...I'm about to start developing a custom business application on top of Sharepoint 2010. I haven't done anything on this product but client insists on it so I don't have a choice. Application info I

  • I am interested in using ASP.Net Mvc 2.0 as the basis for a website but it will need to hook into SharePoint 2007. Am I just dreaming that it is possible or should I just stick with webforms? Has anybody used Mvc as part of SharePoint 2007? What problems did you have to overcome to be able to accomplish it?