Dan on AxCMS.net
Many modern websites use lightboxes to present their image contents.
Wouldn´t it be nice to have an easy way to use lightboxes inside AxCMS.net 8.5? In this post I will show how to create a Lightbox Control to be used inside AxCMS.net 8.5 Premium Template Project.
First we need a Lightbox to start from. Let’s choose the Lightbox2 by Lokesh Dhakar, which is very lightweight and easy to integrate. Thanks for the brilliant work done!
After downloading the LightBox2 code we do an easy setup copying all folders contained in the .ZIP file to the accordant folders of the Premium Template Project inside the AxCMSTemplates_PremiumSample folder. The folder “js” had to be created first.
As the Lightbox2 instructions point out, we need to reference the javascript and css files next. Using the AxCMS.net 8.5 Premium Template Project this task is accomplished best in the LoadCSS() method of the PremiumSampleBaseTemplate class:
1:
3: {
5: {
7: headTag.Controls.Add(new LiteralControl(tag));
9: headTag.Controls.Add(new LiteralControl(tag));
11: headTag.Controls.Add(new LiteralControl(tag));
13: headTag.Controls.Add(new LiteralControl(tag));
15: headTag.Controls.Add(new LiteralControl(tag));
17: headTag.Controls.Add(new LiteralControl(tag));
19: }
Please check the lightbox.js as you need to adjust the loading.gif and closelabel.gif path.
Next thing we need is a control that makes use of a lightbox. We could think of dynamic lists of documents that can be displays as an image gallery, but I suppose we should start with this one:
We will create a dynamic control that points to two documents:
Additionally we would need a caption to show inside the image lightbox.
The ASP.NET Code is quite simple and reflects an image having a link to another image:
1: <asp:HyperLink ID="hyperlink" runat="server">
3: </asp:HyperLink>
The code behind file reads like this:
5:
7: public string Caption
9: get { return _caption; }
11: }
13: private int? _documentID;
15: {
17: set { _documentID = value; }
19:
21: public int? ThumbnailID
23: get { return _thumbnailID; }
25: }
27: protected override void Bind()
29: if (ThumbnailID != null)
31: AxDocument document = (AxDocument)new AxDocumentAdapter().Load((int)_thumbnailID);
33: {
35: }
37:
39: {
41: {
43: if (document != null)
45: hyperlink.Attributes["title"] = Caption;
47: hyperlink.NavigateUrl = CMSConfigurationSettings.VirtualPath + document.Url;
49: }
51: }
The properties Caption, DocumentID and ThumbnailID will be utilized by AxCMS.net later on as we define a custom editor for the control.
The Bind() method firsts checks if there is a thumbnail available. If so, it will be loaded into the image tag. After that the method checks if we are in life system. If so, it tries to load an image document to be shown inside the lightbox using the caption defined.
The custom editor is derived by the FLVPlayerEditor that ships with the Premium Template Project:
1: <table cellpadding="0" cellspacing="5">
3: <td colspan="2">
5: </td>
7: <tr>
9: <axcms:pagecall id="documentPageCall" runat="server" buttontype="LinkButton" target="_blank"
11: </td>
13: <asp:hyperlink id="documentLink" runat="server" target="_blank" />
15: </tr>
17: <td colspan="2">
19: </td>
21: <tr>
23: <axcms:pagecall id="thumbnailPageCall" runat="server" buttontype="LinkButton" target="_blank"
25: </td>
27: <asp:hyperlink id="thumbnailLink" runat="server" target="_blank" />
29: </tr>
31: <td colspan="2">
33: </td>
35: <tr>
37: <asp:literal id="Literal4" runat="server">Lightbox Image Caption</asp:literal>
39: </tr>
41: <td colspan="2">
43: </td>
45: </table>
We just define two document links and a captionTextBox to gather the editors choices. The code behind is "classic" custom editor code. First we define two document links:
3:
5: protected PageCall thumbnailPageCall;
7:
9: {
11: set { ViewState["DocumentID"] = value; }
13:
15: private int? ThumbnailID
17: get { return (int?)ViewState["ThumbnailID"]; }
21:
23: {
25: thumbnailPageCall.NavigateUrl = CMSConfigurationSettings.CMSApplicationVirtualPath + "/admin/documents/DocumentOverview.aspx?Popup=1&Select=1&AxID=" + ThumbnailID.ToString();
27: documentPageCall.ClickAfter += new Axinom.Framework.ExtendedEventHandler(documentPageCall_ClickAfter);
29:
31: private void documentPageCall_ClickAfter(object obj, Axinom.Framework.ExtendedEventArgs e)
33: DocumentID = Convert.ToInt32(e.Name);
41: BindThumbnail();
The BindDocument() and the BindThumbnail() methods read like the following:
5: thumbnailLink.NavigateUrl = null;
7: if (ThumbnailID != null)
9: AxDocument doc = (AxDocument)new AxDocumentAdapter().Load(ThumbnailID);
11: {
13: thumbnailLink.Text = "Document unknown - please select another document!";
15: }
17: {
19: thumbnailLink.NavigateUrl = CMSConfigurationSettings.CMSApplicationVirtualPath + doc.Url;
21: }
23:
25: private void BindDocument()
27: documentLink.Text = string.Empty;
31: if (DocumentID != null)
33: AxDocument doc = (AxDocument)new AxDocumentAdapter().Load(DocumentID);
35: {
37: documentLink.Text = "Document unknown - please select another document!";
39: }
43: documentLink.NavigateUrl = CMSConfigurationSettings.CMSApplicationVirtualPath + doc.Url;
45: }
After that we have two methods to load and save the parameters we defined for the lightbox image control:
{
}
BindDocument();
if (!string.IsNullOrEmpty(Parameters["ThumbnailID"]))
ThumbnailID = System.Convert.ToInt32(Parameters["ThumbnailID"]);
public void SaveParameters()
NameValueCollection parameters = new NameValueCollection();
parameters.Add("DocumentID", DocumentID.ToString());
Parameters = parameters;
Last thing we have to do is to register our newly created control to the cmssite.xml:
<elementtemplatedefinition axid="LightboxImage" description="Lightbox Image">
<IsCompiled>false</IsCompiled>
<Placeholders />
<Parameter>Caption</Parameter>
<Parameter>ThumbnailID</Parameter>
<Editor>~/templates/DynControls/Editor/LightBoxImageEditor.ascx</Editor>
Now – were done. Reference the ElementTemplate in any Placeholder of your choice and serve chilled.
Tags:
Related posts
Comments
4/8/2009 12:40:07 PM #
The controll is nice but not as mach as user-friendly. The editor have to generate both, the thumbnail and the "zoom" image. The better way, such a lot of CMS do, is to generate the thumbnail picture on the fly.
Eugen Richter
4/9/2009 10:56:56 AM #
Hi Eugen, this task can easily be accomplished: just change the custom template to dynamically create the thumbnail image using .net image processing features
dan
4/29/2009 9:11:36 AM #
thank you for your proposal. my new control runs on AxCMS 7.0.0.34122
Ralph
Add comment
Powered by BlogEngine.NET 1.6.1.0 Theme by Mads Kristensen
Dan Wucherpfennig is an IT consultant employed at EDV-Partner (http://www.edvpartner.de), a Hamburg based system integration and consulting company.
Having many years of experience in developing projects with AxCMS.net, Dan has been awarded as an AxConsultant during the AxDays 2008.