Showing posts with label client object model. Show all posts
Showing posts with label client object model. Show all posts

Thursday, September 27, 2012

ECMA scripting

ECMA Scripting and WebParts in Sharepoint.

Hey,

Today I'm planning to present "How to do a webpart using client object model, which is capable of replicating multiple time within a same page". Most of Sharepoint developers developing webparts using client object model with ECMA scripting. However duplicate webparts cant included in a same page.

But below is a nice approach on solving above issue.

1.Create a visual webpart which is inheriting from System.Web.UI.WebControls.WebParts.WebPart
2.In the .cs file just add hidden property with webpart's clienID and
3.Read that client id to commit any changes.

I have attached a sample project consisting this solution. Open the solution from VS 2010.

File structure:




BlogViewer.cs - holding one webpart property, saving the property value to a hidden field, registering the js file, register main function of js - which is having the webpart client id to refer the control/s.

comscript.js - get the webpart client id, access webpart property value - which is already write to the hidden field, then populate the html file inside the webpart div.

control.htm - holding the markup of the webpart

Download from here : ECMAScripting