Kentico CMS 7.0 Developer's Guide

Web part containers and sites

Web part containers and sites

Previous topic Next topic Mail us feedback on this topic!  

Web part containers and sites

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example assigns a web part container to a site.

 

private bool AddWebPartContainerToSite()
{

  // Get the web part container

  WebPartContainerInfo container = WebPartContainerInfoProvider.GetWebPartContainerInfo("MyNewContainer");

    if (container != null)
    {
        int containerId = container.ContainerID;
        int siteId = CMSContext.CurrentSiteID;
 
        // Save the binding
        WebPartContainerSiteInfoProvider.AddContainerToSite(containerId, siteId);
 
        return true;
    }
 
    return false;
}

 

The following example removes a container from a site.

 

private bool RemoveWebPartContainerFromSite()
{

  // Get the web part container

  WebPartContainerInfo removeContainer = WebPartContainerInfoProvider.GetWebPartContainerInfo("MyNewContainer");

    if (removeContainer != null)
    {
        int siteId = CMSContext.CurrentSiteID;
 

      // Delete the binding
      WebPartContainerSiteInfoProvider.RemoveContainerFromSite(removeContainer.ContainerID, siteId);

 
        return true;
    }
 
    return false;
}