How to use the Media gallery web part on an ASPX page template
This article describes how to use the Media gallery web part on an ASPX page template. Most of this approach is general and shows how to use any web part on an ASPX page template. However, in case of the Media gallery web part some additional steps must be taken to make it running properly.
Let´s say we have an existing ASPX page template (if you don’t have one already created, see
how to create a new ASPX page template in Kentico CMS).
First, you need to register a proper web part on your ASPX page like this:
<%----------------Registration of media gallery web part----------------------%>
<%@ Register Src="~/CMSWebParts/MediaLibrary/MediaGallery.ascx" TagName="MediaGallery"
TagPrefix="uc1" %>
<%----------------------------------------------------------------------------%>
Note: The
Src parameter points to a physical file within your solution.
Now, you can use the web part (via its TagPrefix and TagName) in your ASPX code like this:
<uc1:MediaGallery ID="mediaGallery" runat="server" (…) />
Where
(…) represents all required properties.
You need to set them ALL, including ALL transformations and ALL pager-related templates to get it running correctly. A list of all required properties would look like this:
CurrentPageTemplate="CMS.PagerTransformations.General-CurrentPage"
DisplayActiveContent="true" DisplayFileCount="true"
DisplayFirstLastAutomatically="true" DisplayPreviousNextAutomatically="true"
FileIDQueryStringKey="fileid" FilterMethod="0"
FirstPageTemplate="CMS.PagerTransformations.General-FirstPage"
FooterTransformation="Community.Transformations.MediaLibraryFooter"
GroupSize="2"
HeaderTransformation="Community.Transformations.MediaLibraryHeader"
HideFolderTree="true" HidePagerForSinglePage="true"
LastPageTemplate="CMS.PagerTransformations.General-LastPage"
LayoutTemplate="CMS.PagerTransformations.General-PagerLayout"
MediaLibraryName="test"
NextGroupTemplate="CMS.PagerTransformations.General-NextGroup"
NextPageTemplate="CMS.PagerTransformations.General-NextPage" PageSize="9"
PagesTemplate="CMS.PagerTransformations.General-Pages"
PathQueryStringKey="path"
PreviousGroupTemplate="CMS.PagerTransformations.General-PreviousGroup"
PreviousPageTemplate="CMS.PagerTransformations.General-PreviousPage" SelectedItemTransformation="Community.Transformations.MediaLibrarySelectedItem"
SeparatorTemplate="CMS.PagerTransformations.General-PageSeparator" SeparatorTransformation="Community.Transformations.MediaLibraryItemSeparator"
ShowSubfoldersContent="true" SortQueryStringKey="sort"
TransformationName="Community.Transformations.MediaLibrary"
UseSecureLinks="true"
A media gallery you want to get data from is specified by the “MediaLibraryName” property. If you want to show content from a particular folder within this media gallery, you need to specify “MediaLibraryPath” as well.
Unlike in case of a standard web part, you must call all the
ReloadData() method in the
Page_Load event of the given ASPX page. This method is called for a particular web part and ensures that all properties are loaded properly.
Example code of the
Page_Load handler of the ASPX page containing your
Media gallery web part:
protected void Page_Load(object sender, EventArgs e)
{
// this line must be added
this.mediaGallery.ReloadData();
}
Where
mediaGallery is the ID of your web part.
Here you can see the result:
See also: Displaying Media gallery content on your siteApplies to: Kentico CMS 5.x