获取 SharePoint 2007 中 WebPart 的 GUID
我正在尝试发出一些 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这已经很旧了,但我在查询其他内容时遇到了它,并认为“关闭它”可能会有所帮助。 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.
只是好奇,您是否尝试过将 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)