Is it possible to read visual web part custom properties using Java script client object model in SharePoint 2010?
2 Answers
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.
-
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?Harminder Singh– Harminder Singh2014-07-22 16:35:03 +00:00Commented 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?Stefan Hennicken– Stefan Hennicken2014-08-18 11:00:21 +00:00Commented Aug 18, 2014 at 11:00
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