SOLVED

Responsive Visual webpart

%3CLINGO-SUB%20id%3D%22lingo-sub-42689%22%20slang%3D%22en-US%22%3EResponsive%20Visual%20webpart%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-42689%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20are%20evaluating%20if%20we%20create%20a%20visual%20webpart%2C%20will%20we%20be%20able%20to%20make%20it%20responsive%20as%20well%3F%20Considering%20we%20manage%20to%20create%20a%20custom%20master%20page%20and%20custom%20pagelayout%20that%20has%20RWD%20framework%20maybe%20Bootstrap.%3C%2FP%3E%3CP%3ECan%20we%20achieve%20this%20in%20a%20visual%20webpart%20or%20do%20we%20have%20mandatorily%20go%20with%20add-in%20model%20or%20just%20use%20Cotent%20Editor%20webparts%3F%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-42889%22%20slang%3D%22en-US%22%3ERe%3A%20Responsive%20Visual%20webpart%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-42889%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1930%22%20target%3D%22_blank%22%3E%40Devendra%20Singh%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20not%20recommend%20using%20visual%20web%20part%20at%20all%20for%20this%20kind%20of%20things.%20Sometimes%20it's%20harder%2C%20sometimes%20impossible%20(in%20SPO).%20I%20know%20that%20this%20recommendation%20is%20mentioned%20before.%20Just%20telling%20it%20again.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20recommend%20using%20CEWP%20instead%20with%20a%20link%20to%20html%26nbsp%3Bhosted%20in%20SharePoint%20_catalogs%2Fmasterpage%26nbsp%3Bdocument%20library.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ecewp.html%20acts%20as%20a%20container%20for%20your%20JS%2FHTML%2Fweb%20part's%20DOM%2C%20etc.%3C%2FP%3E%3CP%3EThe%20web%20part%20communicates%20with%20SharePoint%20object%20model%20via%20JSOM%20or%20REST%20or%20SOAP%20(yes%20there%20are%20some%20things%20missing%20in%20other%20object%20models)%2C%20depending%20on%20your%20preferences%20and%20functionality.%3C%2FP%3E%3CP%3EResponsiveness%20is%20managed%20by%20your%20CSS%20and%20in%20some%20rare%20cases%20with%20JS.%20It's%20possible%20to%20use%20Bootstrap%20to%2C%20but%20better%20to%20build%20it%20from%20.less%20sources%20excluding%20some%20parts%20(like%26nbsp%3Bnormalize%2C%26nbsp%3Bscaffolding%2C%26nbsp%3Btype)%20%26nbsp%3Bwhich%20break%20SharePoint%20styles%20dramatically.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESuch%20model%20is%20easily%20deployable%20to%20different%20environments%20with%20gulp%20automation.%20You%20could%20check%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fs-KaiNet%2Fgulp-spsave%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Egulp-spsave%26nbsp%3B%3C%2FA%3Eor%20a%20boilerplate%20generator%20-%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fkoltyakov%2Fgenerator-sppp%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Esppp%26nbsp%3B%3C%2FA%3Ewhich%20creates%20a%20project%20capable%20publishing%26nbsp%3Bassests%26nbsp%3Bto%20sharepoint%26nbsp%3Bwithout%20manual%20configuration%20of%20automation%20tasks.%20Some%20Node.js%20background%20is%20needed%2C%20though.%20But%20it%20worth%20it.%20Cause%20you%20receive%20tons%20of%20automation%20capabilities%2C%20including%20live%20reload%20on%20dev%20environments.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%2C%20I%20would%20recommend%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fsubpointsolutions%2Fspmeta2%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3ESPMeta2%3C%2FA%3E%20for%20artifacts%20code%20base%20provisioning%20as%20an%20advanced%20alternative%26nbsp%3Bfor%20PnP%20provisioning%2C%20yet%2C%20PnP%20provisioning%20is%20better%20than%20declarative%20XML%2FCAML%20based%20no%20code%20features%20provisioning.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAll%20of%20the%20mentioned%20above%20is%20easily%20integrated%20to%20the%20DevOps%20to%20repeatable%20deployment%20to%20the%26nbsp%3Bdifferent%20environments.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDealing%20with%20CEWP%20with%20script%20source%20is%20a%20step%20next%20to%20SharePoint%20framework.%20Most%20of%20the%20development%20workflow%20is%20very%20close%20to%20what%20you%20can%20face%20in%20SPFx%20and%20when%20SPFx%20is%20ready%20to%20you%20you'll%20be%20mostly%20ready%20to%20it.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E--%3C%2FP%3E%3CP%3EBest%20regards%2C%3C%2FP%3E%3CP%3EAndrew%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-42846%22%20slang%3D%22en-US%22%3ERe%3A%20Responsive%20Visual%20webpart%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-42846%22%20slang%3D%22en-US%22%3EYeah%2C%20didn't%20mention%20Modern%20sites%2C%20as%20is%20still%20unknown.%20However%2C%20if%20you're%20functionality%20is%20built%20on%20JS%20with%20some%20modern%20framework%20like%20Reactjs%2C%20it%20should%20be%20much%20easier%20to%20convert%20it%20in%20a%20new%20SPFx%20webpart.%3CBR%20%2F%3EAlso%2C%20here%20there's%20a%20sample%20on%20how%20to%20provision%20a%20page%20with%20a%20script%20editor%20webpart%20on%20it%2C%20using%20PnP%20Core%20and%20PnP%20Schema%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-Provisioning-Schema%2Fblob%2Fmaster%2FSamples%2FProvisioningSchema-2016-05-FullSample-02.xml%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-Provisioning-Schema%2Fblob%2Fmaster%2FSamples%2FProvisioningSchema-2016-05-FullSample-02.xml%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-42843%22%20slang%3D%22en-US%22%3ERe%3A%20Responsive%20Visual%20webpart%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-42843%22%20slang%3D%22en-US%22%3ERemote%20provisioning%20is%20the%20answer%20here...you%20don't%20need%20to%20do%20stuff%20manually%2C%20you%20can%20automate%20all%20using%20this%20pattern%20and%20you%20have%20all%20what%20you%20need%20in%20the%20PnP%20project%20in%20GitHub.%20Just%20bear%20in%20mind%20that%20Luis'%20suggestion%20will%20work%20with%20classic%20SPO%20sites%20and%20for%20SharePoint%20OnPremises...with%20modern%20team%20sites%2C%20we%20don't%20know%20yet%20how%20to%20do%20the%20same%20(there%20is%20not%20a%20replacement%20yet%20for%20the%20script%20editor%20webpart)%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-42832%22%20slang%3D%22en-US%22%3ERe%3A%20Responsive%20Visual%20webpart%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-42832%22%20slang%3D%22en-US%22%3E%3CP%3EYes%2C%20correct.%20However%2C%20deploying%20all%26nbsp%3Bof%20these%20(HTML%2FCSS%2FJS)%26nbsp%3Bin%20different%20environments%20and%20stages%20when%20using%20Script%20Editor%20Webpart%20and%20then%20creating%20a%20page%20with%20the%20Script%20editor%20webpart%26nbsp%3Band%20linked%20to%20the%20respective%20HTML%2FCSS%2FJS%20is%20something%20that%20I%20am%20not%20clear%20on.%20Any%20thoughts%20on%20this%3F%3C%2FP%3E%3CP%3EWe%20would%20not%20want%20to%20do%20it%20manually%20in%20all%20the%20different%20environments.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-42770%22%20slang%3D%22en-US%22%3ERe%3A%20Responsive%20Visual%20webpart%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-42770%22%20slang%3D%22en-US%22%3EI%20do%20not%20suggest%20a%20Visual%20Webpart%2C%20as%20it's%20kind%20of%20%22deprecated%22%2C%20and%20if%20at%20some%20point%20you%20want%20to%20move%20to%20SP%20Online%2C%20you%20won't%20be%20able%20to%20use%20it.%20I'd%20suggest%20to%20create%20a%20Script%20Editor%20WP%20with%20the%20proper%20HTML%2C%20and%20a%20piece%20of%20JS%20with%20the%20functionality%2C%20using%20REST%20API%20or%20SP%20JSOM.%20Also%2C%20you%20can%20extract%20most%20of%20the%20JS%20code%20to%20an%20external%20JS%20file%20stored%20in%20the%20Style%20library%2C%20and%20just%20place%20the%20HTML%20and%20the%20JS%20%22init%22%20call%20in%20the%20Script%20Editor%20WP.%3C%2FLINGO-BODY%3E
Highlighted
Contributor

We are evaluating if we create a visual webpart, will we be able to make it responsive as well? Considering we manage to create a custom master page and custom pagelayout that has RWD framework maybe Bootstrap.

Can we achieve this in a visual webpart or do we have mandatorily go with add-in model or just use Cotent Editor webparts? 

5 Replies
Highlighted
I do not suggest a Visual Webpart, as it's kind of "deprecated", and if at some point you want to move to SP Online, you won't be able to use it. I'd suggest to create a Script Editor WP with the proper HTML, and a piece of JS with the functionality, using REST API or SP JSOM. Also, you can extract most of the JS code to an external JS file stored in the Style library, and just place the HTML and the JS "init" call in the Script Editor WP.
Highlighted

Yes, correct. However, deploying all of these (HTML/CSS/JS) in different environments and stages when using Script Editor Webpart and then creating a page with the Script editor webpart and linked to the respective HTML/CSS/JS is something that I am not clear on. Any thoughts on this?

We would not want to do it manually in all the different environments.

Highlighted
Remote provisioning is the answer here...you don't need to do stuff manually, you can automate all using this pattern and you have all what you need in the PnP project in GitHub. Just bear in mind that Luis' suggestion will work with classic SPO sites and for SharePoint OnPremises...with modern team sites, we don't know yet how to do the same (there is not a replacement yet for the script editor webpart)
Highlighted
Yeah, didn't mention Modern sites, as is still unknown. However, if you're functionality is built on JS with some modern framework like Reactjs, it should be much easier to convert it in a new SPFx webpart.
Also, here there's a sample on how to provision a page with a script editor webpart on it, using PnP Core and PnP Schema:

https://github.com/SharePoint/PnP-Provisioning-Schema/blob/master/Samples/ProvisioningSchema-2016-05...
Highlighted
Best Response confirmed by Devendra Singh (Contributor)
Solution

Hi @Devendra Singh,

 

I would not recommend using visual web part at all for this kind of things. Sometimes it's harder, sometimes impossible (in SPO). I know that this recommendation is mentioned before. Just telling it again.

 

I would recommend using CEWP instead with a link to html hosted in SharePoint _catalogs/masterpage document library.

 

cewp.html acts as a container for your JS/HTML/web part's DOM, etc.

The web part communicates with SharePoint object model via JSOM or REST or SOAP (yes there are some things missing in other object models), depending on your preferences and functionality.

Responsiveness is managed by your CSS and in some rare cases with JS. It's possible to use Bootstrap to, but better to build it from .less sources excluding some parts (like normalize, scaffolding, type)  which break SharePoint styles dramatically.

 

Such model is easily deployable to different environments with gulp automation. You could check gulp-spsave or a boilerplate generator - sppp which creates a project capable publishing assests to sharepoint without manual configuration of automation tasks. Some Node.js background is needed, though. But it worth it. Cause you receive tons of automation capabilities, including live reload on dev environments.

 

Also, I would recommend SPMeta2 for artifacts code base provisioning as an advanced alternative for PnP provisioning, yet, PnP provisioning is better than declarative XML/CAML based no code features provisioning.

 

All of the mentioned above is easily integrated to the DevOps to repeatable deployment to the different environments.

 

Dealing with CEWP with script source is a step next to SharePoint framework. Most of the development workflow is very close to what you can face in SPFx and when SPFx is ready to you you'll be mostly ready to it.

 

--

Best regards,

Andrew