1

I want to update some custom WebPart properties of a visual WebPart. Right now, I'm able to update the correct WebPart by checking it's title. Here's what I mean:

function GoToGalleryWebPartPage(pageNo) {
    var currentCtx = SP.ClientContext.get_current();
    var pageFile = currentCtx.get_web().getFileByServerRelativeUrl(_spPageContextInfo.serverRequestPath);
    var webPartManager = pageFile.getLimitedWebPartManager(SP.WebParts.PersonalizationScope.shared);
    var webPartDefs = webPartManager.get_webParts();
    currentCtx.load(webPartDefs, 'Include(WebPart.Properties)');
    currentCtx.executeQueryAsync(function () {          
        <%--
        if (webPartDefs.get_count()) {
            for (var i = 0; i < webPartDefs.get_count() ; i++) {
                var webPartDef = webPartDefs.getItemAtIndex(i);
                var webPartSingle = webPartDef.get_webPart();       
                var properties = webPartSingle.get_properties();
                alert(webPartManager.WebParts(0).ClientID);

                // Check the title of the webpart to see if it's the webpart we want.
                if (properties.get_fieldValues()['Title'] == "My Web Part") {
                    properties.set_item("PageNo", pageNo);
                    webPartDef.saveWebPartChanges();

                    currentCtx.load(webPartDef);
                    currentCtx.executeQueryAsync(success, failure);
...

However, this becomes a problem when there are two instances of the same WebPart on the same page as they will have the same title.

I'm thinking of using ClientID instead as it is unique. However, I can't seem to find a way no matter how hard I try. Is there even a way to get the clientID of webparts?

If you can suggest better/alternative ways of solving the problem, please let me know as well.

1
  • Check an answer to this question :) Commented May 5, 2017 at 10:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.