Blue Theme Orange Theme Green Theme Red Theme
 
ASP.NET Web Hosting – Click Here
Home | Forums | Videos | Photos | Blogs | E-Books | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article 
 Login Close
User Id:
Password:
 
Forgot Password
Forgot Username
Why Register
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
LeftbarAd
 Resources  
Close
 Our Network  
Close
Search :       Advanced Search »
Home » ASP.NET & Web Forms » Using Lightbox in an ASP.NET Application (C#)

Using Lightbox in an ASP.NET Application (C#)

The article describes Lightbox as, "... a simple, unobtrusive script used to overlay images on the current page." It delivers a nice, professional looking method for displaying images as overlays through the use of hyperlinks.

Author Rank:
Technologies: ASP.NET 2.0, ASP.NET 3.5,Visual C# .NET
Total downloads : 609
Total page views :  18939
Rating :
 3.67/5
This article has been rated :  3 times
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
Download Files:
LightBoxDemoCS.zip
 
ArticleAd
Become a Sponsor





Introduction

Lightbox 2 is a free download made available by Lokesh Dhakar on this website:

http://www.huddletogether.com/projects/lightbox2

The site describes Lightbox as, "... a simple, unobtrusive script used to overlay images on the current page." It delivers a nice, professional looking method for displaying images as overlays through the use of hyperlinks. Implementation of Lightbox is quite simple involving nothing more that adding some JavaScript and a style sheet to the page and then adding some simple attributes to each link where the effect is to be used. The download includes all of the images, style sheets, and JavaScript necessary to implement Lightbox.

Lightbox allows the developer the option of displaying images singly or in sequence. Images grouped into sequences may be viewed by the user in a slideshow like presentation that the user can control with either the mouse or the left and right arrow keys. All in all, it is a nice way to present a image gallery of thumbnails. As each image is displayed, the control is resized to fit the image and the image is centered on the page. If the image is too large, it will overrun the page so it is important to resize the images so that they will fit within the space available. Once the image is displayed, the user may click off the image or hit the Escape key in order to return to the page.



Figure 1: Lightbox in Use within an ASP.NET Web Application



Figure 2: Lightbox at Rest within an ASP.NET Web Application
(Clicking a link or an image will launch the image into Lightbox)

Getting Started

In order to get started, unzip the included project and save it to your hard drive. Open the web application and examine the contents in the solution explorer.



Figure 3: Solution Explorer

The solution contains a single web application entitled, "LightBoxDemo". The solution contains three added folders: css, images, and js. These folders contain the style sheet, images, and JavaScript provided with the Lightbox download. Additional images were added to the images folder to support the demonstration project. If starting a new project, just create the three folders using these folder names and then copy the contents over into each of the folders from the Lightbox 2 download.

Code: Default.aspx.cs

No additional code was provided to the default page's code behind file. It is in its default condition and is shown here to illustrate that no coding is required to make use of Lightbox 2.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
   {

     }
}


Code: Default.aspx

What little work is required to implement Lightbox 2 is contained in the Default.aspx file itself.

The markup starts with the following unmodified, default code:

<%@ Page="" Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

The first bit of actual work is contained in the head section of the markup; here the JavaScript is references as is the style sheet:

<head runat="server">
       <%--javascript references="" for="" lightbox--=""%>
        <script type="text/javascript" src="js/prototype.js"></script>
        <script type="text/javascript"
        src="js/scriptaculous.js?load=effects,builder"></script>
       <script type="text/javascript" src="js/lightbox.js"></script>
         <%--stylesheet for="" lightbox--=""%>
          <link rel="stylesheet" href="css/lightbox.css" type="text/css"
         media="screen" />
           <%--page title--=""%>
           <title>Lightbox Demo</title>
</head>

Next up, within the form, the first example shows using a simple link to an image; the "rel" tag defines the relationship to the Lightbox style sheet and that is pretty much all that you need to do to evoke the effect.

<body bgcolor="Black"> 
      <
form id="form1" runat="server" style="background-color: #000000; color:
FFFFFF">
         <%--single image="" hyperlink--=""%>
          <div>
            Single Image<br /><br />
            <br />
            <
a href="images/image-1.jpg" rel="lightbox" title="Plant
Life">Look at This Plant</a>
            <br /><br />
          </
div>

The next example shows how to setup a sequence of images. The defined sequence may be controlled by the user with either the mouse or the left and right arrow keys (to move back and forth through the images). Note the passing of "roadtrip1" to Lightbox; all links using 'roadtrip1' will be treated as a group of images. In this case, there are three images using that name and so those three images are treated as a single series; other images on the page that do not use 'roadtrip1' are ignored. This example as well as the next both display thumbnail versions of the image.

   <%--using multiple="" images="" in="" a="" sequence="", link="" is="" thumbnail="" of="" image--=""%>
            <div>
              Raccoons<br /><br />
 
              <
a href="images/bottletree1.JPG" rel="lightbox[roadtrip1]"
              title="Raccoons and Baby Bottles">
                <img src="images/bottletree1.JPG" width="60" height="60" alt="" />
             </
a>

               <a href="images/bottletree2.JPG" rel="lightbox[roadtrip1]"
              title="Sugar Water Bottles">
                <img src="images/bottletree2.JPG" width="60" height="60" alt="" />
             </
a>

               <a href="images/bottletree3.JPG" rel="lightbox[roadtrip1]"
              title="More Sugar Water">
                <img src="images/bottletree3.JPG" width="60" height="60" alt="" />              </a
            </
div>
            <
br />
            <
br />
            <
br />
            <
br />

The last example shows how to setup a second sequence of images; note that these images are banded together as 'roadtrip2' and as such they will be kept separate from the other images on this page when viewed using Lightbox:

            <%--using multiple="" images="" in="" a="" sequence="", link="" is="" thumbnail=""
of="" image--=""%>
              <div>
                Birds<br /><br />

                <a href="images/AmericanGoldfinch_male.jpg" rel="lightbox[roadtrip2]"
                title="American Goldfinch">
                  <img src="images/AmericanGoldfinch_male.JPG" width="60" height="60"
                  alt="" />
               </a>

                 <a href="images/birdgroup1.jpg" rel="lightbox[roadtrip2]"
                title="Mixed Birds">
                  <img src="images/birdgroup1.JPG" width="60" height="60" alt="" />
                </a
                <
a href="images/doves.jpg" rel="lightbox[roadtrip2]"
                title="Mourning Doves">
                  <img src="images/doves.JPG" width="60" height="60" alt="" />
                </a>
                <
a href="images/goldfinch_fiesta.jpg" rel="lightbox[roadtrip2]"
                title="American Goldfinches">
                  <img src="images/goldfinch_fiesta.JPG" width="60" height="60" alt="" />
                </
a>

                <a href="images/hummingbird.jpg" rel="lightbox[roadtrip2]"
                title="Ruby Throated Hummingbird">
                  <img src="images/hummingbird.JPG" width="60" height="60" alt="" />
                </
a>

                <a href="images/RoseBreastedGrosbeak_male.jpg"
                rel="lightbox[roadtrip2]"
                title="Rose Breasted Grosbeak">
                  <img src="images/RoseBreastedGrosbeak_male.JPG" width="60"                   height="60" alt="" />
                </a>

             </
div>
            </form>
     </body>
  </
html>

Summary

Lightbox 2 is sort of a fun little tool that is very useful if one wants to display images from either links or thumbnail versions of an image. I thought it was a good find that simplified the process of displaying a large or small number of images in an interesting way and of course the price is perfect.


Login to add your contents and source code to this article
 [Top] Rate this article
 About the author
 
Scott Lysle
Freelance software developer residing in Alabama. Bachelors, Masters Degrees from Wichita State University. I spent the first half of my career working on aircraft controls and displays and in that time I worked on the cockpits for the OH-58 AHIP, the AH-1W, the V-22, the F-22, the C-130J, the C-5 AMP, AWACS, JPATS, and a few others. Since 1997 I have been largely involved with Windows and web development, GIS application development, consumer electronics development (embedded linux/java), but still sometimes work on aircraft and military projects, the most recent of which was the presidential transport helicopter. I tend to work primarily with C/C++, Java, VB, and C#.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Boost the performance of your .NET applications
“ANTS Profiler took us straight to the specific areas of our code which were the cause of our performance issues." Terry Phillips, Sr. Developer, Harley-Davidson Dealer Systems. Download your free trial of ANTS Profiler.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today.  With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications.  Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
 
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
Download Files:
LightBoxDemoCS.zip
 
 Post a Feedback, Comment, or Question about this article
Subject:  
Comment:  
ArticleAd
Become a Sponsor
Latest Comments:
Subject Posted By Posted On
asp.netsherwin5/4/2009
I will try
Reply | Email | Delete | Modify | 
Jquerygagga5/25/2009
Is the same as the jQuery plugin, http://leandrovieira.com/projects/jquery/lightbox/ ?


Reply | Email | Delete | Modify | 
 
 
Re: JqueryScott5/26/2009
It was not at time so far as I know but it is not a surprise to see it as a jquery plug-in.
Reply | Email | Delete | Modify | 
Lightbox Projects Listfreezesoul5/26/2009
http://hi.baidu.com/freezesoul/blog/item/0083c0fd4eb7cc40d7887d63.html

Lightbox Projects List
Reply | Email | Delete | Modify | 
 
 
Re: Lightbox Projects ListScott5/26/2009
Interesting stuff; I liked the Lightbox gone wild demo.
Reply | Email | Delete | Modify | 
thank you Scott Lyslemvpajun5/26/2009
hi,this demo is very cool,i must say that thank you by my heart .
and i like this articles .
Reply | Email | Delete | Modify | 
 
 
Re: thank you Scott LysleScott5/27/2009
Thanks
Reply | Email | Delete | Modify | 
lightboxashraf5/27/2009
i want to use this demo in my project to school. do i have the rights to do that?
and thank u for a nice article
Reply | Email | Delete | Modify | 
 
 
Re: lightboxScott5/27/2009
Sure, you can use it anyway you see fit.
Reply | Email | Delete | Modify | 
tanqRama6/25/2009
i am very lucky to hav this site
Reply | Email | Delete | Modify | 

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2009.6.2
 © 1999 - 2009  Mindcracker LLC. All Rights Reserved