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?