我需要我的jquery展开和折叠代码才能实际回写到Webpart Manager。例如,如果webpart已经最小化,其状态将被记住。例如,如果页面被刷新,则将保留个性化设置。
Theroy 1。
使用WCF服务,该服务将由具有webparts id的jquery代码调用。然后,Wcf服务将简单地更新webpart的状态
理论2。 选择最小化时,调用sharepoint调用的相同javascript函数。一直试图找到它似乎
有什么建议吗?
答案 0 :(得分:0)
我通过构建WCF服务来完成这项工作,该服务执行以下操作;
当webpart最小化时,guid是jquery ajax调用传递的webpart客户端ID
public string UpdateCurrentWebPart(string guidString) {
SPWeb myweb = SPContext.Current.Web;
myweb.AllowUnsafeUpdates = true;
//only want the webparts with have personal settings
using (SPLimitedWebPartManager mgr = myweb.GetLimitedWebPartManager("pages/default.aspx", PersonalizationScope.User))
{
string result = "Not found " + guidString;
//find my webpart
foreach (System.Web.UI.WebControls.WebParts.WebPart _webpart in mgr.WebParts)
{
if (guidString.Contains(_webpart.ClientID))
{
try
{
//toggle it
if (_webpart.ChromeState == PartChromeState.Minimized)
{
_webpart.ChromeState = PartChromeState.Normal;
}
else
{
_webpart.ChromeState = PartChromeState.Minimized;
}
//save it
mgr.SaveChanges(_webpart);
//useful for debugging
result = guidString + _webpart.ChromeState.ToString();
}
catch
{
}
}
}
return result;
}