获取 SharePoint 2007 中 WebPart 的 GUID

发布于 2024-08-28 22:55:09 字数 1450 浏览 2 评论 0原文

我正在尝试发出一些 jQuery 和其他 Javascript,它们将在页面上隐藏和显示 WebPart。我想做的是找到以下两件事之一:

  • 包含 WebPart 的表格单元格的 ID(即 MSOZoneCell_WebPartWPQ5)
  • HTML 中显示的 WebPart 的 div 选项卡的 WebPartID(即 WebPartID="059611a7-adef -479e-bda9-fe5799dc62d1")

我使用以下代码查看了我想要影响的区域中的 WebPart:

        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
                    // 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);
                    }
                }
            }

问题是 WebPart 或 WebPartManager 的 API 似乎都没有提供此信息。是否可以派生这两个 ID 之一?

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
                    // 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

家住魔仙堡 2024-09-04 22:55:09

我知道这已经很旧了,但我在查询其他内容时遇到了它,并认为“关闭它”可能会有所帮助。 Rob 正在寻找(并且可能很久以前就找到了)的 Microsoft.SharePoint.WebPartPages.WebPart 属性是 StorageKey 属性。

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.

待"谢繁草 2024-09-04 22:55:09

只是好奇,您是否尝试过将 Web 部件转换为 Microsoft.SharePoint.WebPartPages.WebPart 并从中访问 ID?

(来自 http://msdn.microsoft。 com/en-us/library/microsoft.sharepoint.webpartpages.webpart.id.aspx

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文