none
Custom ASP.NET Controls i Sharepoint solutions

Réponses

  • A visual webpart is just a standard asp.net 2.0 webpart that is doing Page.LoadControl on an ascx control deployed to the controls templates folder.  The visual webpart is merely a visual studio item template that makes the task of coupling an ascx control to a webpart easier (automatic) and automatically registers the ascx and webpart controls as safe controls in the web.config when the package is deployed.

    Using ASCX controls without a backing webpart is useful when you need to design controls that will be used on application pages (e.g. _Layouts/SomePage.aspx) where there is no web part manager.  WebParts can still be used on webpart pages but sometimes they are just not necessary or not needed in the design. For example, I wrote a JCROP enable user profile picture uploader a while back.  This control was designed to be used in a dialog which resides on an application page.  There was no need for a webpart, so I just made it an ascx control and deployed it to _ControlTemplates/XYZ/Jcrop/JcropProfilePicture.ascx

    Making controls safe is also an easy task, as you can use a Module that does nothing, in properties in solution explorer there is a section to register safe controls, or you can use the Package designer to register all types in your dll (aka the wsp) as being Safe.

    Deployment wise, they are deployed the exact same way.

    Deployment options

    1. Deploy from visual studio, the files will be copied to the controltemplates folder

    2.  Deploy with an external tool that does an Update-SPSolution on the wsp, the files will be copied to the controltemplates folder

    3.  Use the CKSDev Visual Studio extension, it provides a new menu on right clicking the project called quick deploy, this will copy the files to the control templates folder and allow you to make markup changes without recylcing the application pool.

    Webparts deploy the same way.  The only real different is your missing the webpart wrapper.  All a Visual WebPart is, is a Wrapper for an ASCX control, that's how it gives you ASCX design support, by wrapping an ASCX control with Page.LoadControl(some ascx path here).

    A non visual webpart assumes you will create the markup via code, or maybe use xslt transformations.


    My Blog: http://www.thesug.org/Blogs/ryan_mann1/default.aspx Website: Under Construction

    lundi 18 juin 2012 16:54
  • Deploying to GAC is not manual. While building the package, you can add assemblies which should go to GAc along with the project assembly. With that , a safe control entry is required to be entered too (VS2010). Thats automates deployment for gac deployment for all WFE.

    Ashish Ranjan (Please click "Marked As Answer" if a post solves your problem or "Vote As Helpful" if a post has been useful to you)

    lundi 18 juin 2012 16:59
  • >>1) What is the reason for this as opposed to using webparts?

    Hi, sometimes there is no need to create webpart.

    For example when you are creating something not in the main area of the page.

    For controls you don't need to create webpart zone and you don't have any menus for closing, presetting webpart etc...

    You also can place control even to master pages, but you can't do it with webparts. You can use controls completely anywhere. You can use webparts only in certain cases when you have webpart zone on layout pages.

    There is also no need to activate any features for using controls. The only need is marking controls or its namespace as safe.

    >>2) When these are written, how are they deployed / where are they used on the site? IE are they in page layouts developed in visual studio - if so, how is that done?

    Controls can be created by two ways:

    1)ascx controls are stored in controltemplates directory. You need to use mapped folder "Controltemplates" in Sharepoint solution for this. If any codebehind file is specified, than this codebehind logic is placed into DLL library in the GAC or bin folder.

    2)web controls (.cs file only with class inherited from Control class) are stored inside DLL in Global assembly cache/bin folder

    In both ways you can use controls at any page.


    Ivan Gorbadey. Sharepoint 2010 MCPD & MCITP.




    lundi 18 juin 2012 17:06
  • Since were talking ascx files, I'm assuming you have your wsp scoped as a farm solution since ascx files cannot be deployed in a sandboxed solution as sandboxed solutions do not have write access to the file system.

    Farm scoped solutions have to be deployed to the gac to the best of my knowledge.


    My Blog: http://www.thesug.org/Blogs/ryan_mann1/default.aspx Website: Under Construction

    mardi 19 juin 2012 16:54

Toutes les réponses

  • A visual webpart is just a standard asp.net 2.0 webpart that is doing Page.LoadControl on an ascx control deployed to the controls templates folder.  The visual webpart is merely a visual studio item template that makes the task of coupling an ascx control to a webpart easier (automatic) and automatically registers the ascx and webpart controls as safe controls in the web.config when the package is deployed.

    Using ASCX controls without a backing webpart is useful when you need to design controls that will be used on application pages (e.g. _Layouts/SomePage.aspx) where there is no web part manager.  WebParts can still be used on webpart pages but sometimes they are just not necessary or not needed in the design. For example, I wrote a JCROP enable user profile picture uploader a while back.  This control was designed to be used in a dialog which resides on an application page.  There was no need for a webpart, so I just made it an ascx control and deployed it to _ControlTemplates/XYZ/Jcrop/JcropProfilePicture.ascx

    Making controls safe is also an easy task, as you can use a Module that does nothing, in properties in solution explorer there is a section to register safe controls, or you can use the Package designer to register all types in your dll (aka the wsp) as being Safe.

    Deployment wise, they are deployed the exact same way.

    Deployment options

    1. Deploy from visual studio, the files will be copied to the controltemplates folder

    2.  Deploy with an external tool that does an Update-SPSolution on the wsp, the files will be copied to the controltemplates folder

    3.  Use the CKSDev Visual Studio extension, it provides a new menu on right clicking the project called quick deploy, this will copy the files to the control templates folder and allow you to make markup changes without recylcing the application pool.

    Webparts deploy the same way.  The only real different is your missing the webpart wrapper.  All a Visual WebPart is, is a Wrapper for an ASCX control, that's how it gives you ASCX design support, by wrapping an ASCX control with Page.LoadControl(some ascx path here).

    A non visual webpart assumes you will create the markup via code, or maybe use xslt transformations.


    My Blog: http://www.thesug.org/Blogs/ryan_mann1/default.aspx Website: Under Construction

    lundi 18 juin 2012 16:54
  • Deploying to GAC is not manual. While building the package, you can add assemblies which should go to GAc along with the project assembly. With that , a safe control entry is required to be entered too (VS2010). Thats automates deployment for gac deployment for all WFE.

    Ashish Ranjan (Please click "Marked As Answer" if a post solves your problem or "Vote As Helpful" if a post has been useful to you)

    lundi 18 juin 2012 16:59
  • >>1) What is the reason for this as opposed to using webparts?

    Hi, sometimes there is no need to create webpart.

    For example when you are creating something not in the main area of the page.

    For controls you don't need to create webpart zone and you don't have any menus for closing, presetting webpart etc...

    You also can place control even to master pages, but you can't do it with webparts. You can use controls completely anywhere. You can use webparts only in certain cases when you have webpart zone on layout pages.

    There is also no need to activate any features for using controls. The only need is marking controls or its namespace as safe.

    >>2) When these are written, how are they deployed / where are they used on the site? IE are they in page layouts developed in visual studio - if so, how is that done?

    Controls can be created by two ways:

    1)ascx controls are stored in controltemplates directory. You need to use mapped folder "Controltemplates" in Sharepoint solution for this. If any codebehind file is specified, than this codebehind logic is placed into DLL library in the GAC or bin folder.

    2)web controls (.cs file only with class inherited from Control class) are stored inside DLL in Global assembly cache/bin folder

    In both ways you can use controls at any page.


    Ivan Gorbadey. Sharepoint 2010 MCPD & MCITP.




    lundi 18 juin 2012 17:06
  • Hi,

    Thanks for the answers. I am just not sure about deploying to GAC. When should I do this? If I need to do this, the assembly of the VS2010 would go in there and the ascx in CONTROLTEMPLATES? To deploy in GAC, I could just do a standard deployment of the wsp (this is a wsp with just the ascx files) and use the -GACDeployment switch, I assume?


    • Modifié GSS1 mardi 19 juin 2012 11:21
    mardi 19 juin 2012 11:17
  • Since were talking ascx files, I'm assuming you have your wsp scoped as a farm solution since ascx files cannot be deployed in a sandboxed solution as sandboxed solutions do not have write access to the file system.

    Farm scoped solutions have to be deployed to the gac to the best of my knowledge.


    My Blog: http://www.thesug.org/Blogs/ryan_mann1/default.aspx Website: Under Construction

    mardi 19 juin 2012 16:54