How to add a web part on page in such a way that we later on can find it (using CSOM) - Can we somehow store identifier information to the web part? Say user could change the title and description (so they cannot be used as identifiers).
Or do we have to use (asmx) web services..
Edit
Appears asmx is needed. Vadim proposes JavaScript solution below. Here also simple server-side code (client uses _vti_bin/WebPartPages.asmx)
XElement resultElement = client.GetWebPartProperties2("/SitePages/DevHome.aspx", Storage.Shared, SPWebServiceBehavior.Version3);
var webParts = new List<Dictionary<string,string>>();
foreach (XNode webPartNode in resultElement.Nodes())
{
var properties = new Dictionary<string,string>();
XElement element = webPartNode as XElement;
foreach (XNode propertyNode in element.Nodes())
{
XElement propertyElement = propertyNode as XElement;
if (propertyElement != null)
{
properties.Add(propertyElement.Name.LocalName, propertyElement.Value);
}
}
webParts.Add(properties);
}
Edit2 As Ali points below we could use web part guid as the identifier: we would get it while creating the web part, store it to an external location, and use it later on. However, in this case we cannot use/store this identifier but need to provide our own. Thus the only remaining possibility seems to be asmx.