开发者

Get the GUID of a WebPart in SharePoint 2007

开发者 https://www.devze.com 2022-12-26 13:40 出处:网络
I\'m trying to emit some jQuery and other Javascript that will hide and show WebParts on a page. What I\'d like to do is find one of two things:

I'm trying to emit some jQuery and other Javascript that will hide and show WebParts on a page. What I'd like to do is find one of two things:

  • The ID of the table cell that contains the WebPart (i.e. MSOZoneCell_WebPartWPQ5)
  • The WebPartID of the div tab of the WebPart that shows in the HTML (i.e. WebPartID="059611a7-adef-479e-bda9-fe5799dc62d1")

I've looked at the WebParts in the Zone I want to impact using the following code:

        System.Web.UI.WebControls.WebParts.WebPartZoneBase
        myZone = this.Zone;

        if (myZone != null)
        {

            for (int i = 0; i < myZone.WebParts.Count; i++)
            {
                // Get the web part
                System.Web.UI.WebControls.WebParts.WebPart wp =
                    myZone.WebParts[i] as System.Web.UI.WebControls.WebParts.WebPart;
                if (wp != null)
                {
                    // Build an XPath query to get the attribute for
                开发者_Go百科    // this web part
                    string xpathQuery = "/tabs/tab[@name='" + wp.Title + "']";

                    XmlElement wpElement =
                        tabConfigDoc.SelectSingleNode(xpathQuery) as XmlElement;

                    if (wpElement != null)
                    {                            
                        hideTabsJS.AppendFormat("$(\"#{0}\").hide(); ", wp.ID);
                        //switchTabsJS.AppendFormat("$(\"#{0}\").hide(); ", wp.ClientID);
                    }
                }
            }

The problem is that none of the APIs for the WebPart or WebPartManager seem to provide this information. Is it possible to derive one of the two IDs?


I know this is old, but I came across it querying for something else, and thought it might be helpful to "close it out.". The Microsoft.SharePoint.WebPartPages.WebPart property Rob was looking for (and has probably long ago found) is the StorageKey property.


Just of curiosity, have you tried casting the web parts as Microsoft.SharePoint.WebPartPages.WebPart and accessing the ID from that?

(from http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.webpart.id.aspx)

0

精彩评论

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