3

Is it possible to read visual web part custom properties using Java script client object model in SharePoint 2010?

2 Answers 2

1

You cannot read directly from the webpart. But you can however write the values out in the control.

Controls.Add(new LiteralControl(String.Format("<script type='javascript'>var customWebPartProperty1 = '{0}';</script>", myWebPart.CustomProperty1)));

You can also write them to hidden fields in the webpart instead if that makes it easier.

2
  • Thanks Daniel. currently i am writing the value in hidden field. it seems it is possible in sp2013 [link]msdn.microsoft.com/en-us/library/office/…. as get_properties() is available which is not there in sp 2010. [link]msdn.microsoft.com/en-us/library/office/…. Is it possible to read properties value using SPServices or any other clientside js? Commented Jul 22, 2014 at 16:35
  • It seems like get_properties() only gets the built-in-properties of the Webpart in SP2013. Did you get further information about custom properties? Commented Aug 18, 2014 at 11:00
0

i use this JS code to get the values of the custom properties i created.

 var propVal = decodeURIComponent(getQueryStringParameter("MyPropName"));

//when getquerystringparameter is undefined you can also copy paste this

function getQueryStringParameter(paramToRetrieve) {
        var params =
            document.URL.split("?")[1].split("&");
        var strParams = "";
        for (var i = 0; i < params.length; i = i + 1) {
            var singleParam = params[i].split("=");
            if (singleParam[0] == paramToRetrieve)
                return singleParam[1];
        }
    }

no idea if this works in 2010 , hope it helps

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.