开发者

Sharepoint 2010 WebParts Jquery Minimize Writing back to the WebPArt Manager

I need my jquery expand and collapse code to actually write back to the Webpart Manager. Eg if a webpart has been minimized its state would be remembered. Eg if the page was refreshed the personnalized setting wo开发者_如何学运维uld be retained.

Theroy 1.

User a WCF service which would be call by the jquery code with the webparts id. The Wcf service would then simple just update the state of the webpart

Theory 2. Call the same javascript function which sharepoint calls when minimize is selected. Been trying to find it appears to be

Any suggestions?


I got this working by building a WCF service which did the following;

the guid is the the webpart client id passed by the jquery ajax call, when the webpart is minimized

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;

        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜