A Simple ASP.NET Flickr Application – Part 2

This is a second part of the article, if you missed the previous post you can find it here:
A Simple ASP.NET Flickr Application – Part 1

To download the source code click here.

Table of contents

A Simple ASP.NET Flickr Application – Part 1

  1. Introduction
  2. Getting started
  3. The web.config

A Simple ASP.NET Flickr Application – Part 2

  1. Constructing the page
  2. The make up
  3. The result
  4. Notes

Constructing the page

Add a new web form to your project and place inside it a DropDownList. After that, place inside the page an ObjectDataSurce control. For this ObjectDataSurce control, you can use the Designer and the Smart Task for making things quicker.

List of default user sets:

As you can see, our method is expecting a value so it can properly retrieve the data. As our user ID is stored in theweb.config, this is the approach for passing a requested argument:

protected void odsSets_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
   e.InputParameters["userId"] = ConfigurationManager.AppSettings["defaultUser"].ToString();

Intercept the Selecting event and manually set the expected parameter. I’m getting it from the web.config; you can choose any other way, e.g.: using another control in the page (if you create a user search). If you are inexperienced, you may be wondering how I got the DataTextField and DataValueField values. Simple, they are properties of the Photoset class, which is an element of PhotosetCollection, that is our called method return type. To explore other properties, create an instance of the Photoset class, select it, and hit F12.

Now I will add a ListView control in order to list the data that is the outcome of my query.

        No data was returned.
        " rel="images" title="<%# Eval("Title") %>">
            " />
Page of
Total Pictures in this set:

Note that I specified a very simple ItemTemplate; the code speaks for itself. The important thing to note is that inside the layout template, there is a DataPager control. When the DataPager is inside a ListView control, setting the PagedControlID of the DataPager isn’t necessary. The container ListView is automatically associated as the paged control.

Obviously, this will not work without a data source, so here we go, an ObjectDataSource is served.


You can use Designer and the Smart Task, but be aware that a guided procedure will add the parameters that are used for paging and the app will not work correctly. Take a look at the properties that enable paging and the count method.

Now we need to set a maximum rows property, but as this property is specified in the web.config, we will do it from code.

protected void odsPhotos_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
   e.Arguments.MaximumRows =

That’s almost it, but there are some small problems, like viewing the second page of a set and then changing the set, setting one that has just one page. Badly sad, more simply, at each set change, we need to reset the page counter.

protected void ddlSets_SelectedIndexChanged(object sender, EventArgs e)
    DataPager pgr = lvImages.FindControl("DataPager1") as DataPager;
    if (pgr != null && lvImages.Items.Count != pgr.TotalRowCount)
        pgr.SetPageProperties(0, pgr.MaximumRows, false);

Now, that’s it, and everything should work perfectly!


Let’s get rid of postbacks. Add on the page a ScriptManager and make the following changes:

Surround the ListView with the following code:

        // my list view

As the DropDownList is outside of the ListView, we need to indicate that even that control triggers a postback and that should be managed properly. Can’t be simpler!

The make up

I said before that we will use a lighbox plug-in called Colorbox. So let’s set it up. First of all, put all the images that are coming with this plug-in into the images directory, then do the same for the CSS style. Open the CSS file that you just copied, and check the image paths. Pay attention to comments about IE workarounds and the connected paths. Copy the necessary scripts to a script folder and then be ready for some code. We should link our scripts and the CSS file, so in the page head, add the following:

Once we are done, we need to create an instance of Colorbox in order for this to work. As the JavaScript is no longer “bound” after a callback made via UpdatePanel, we need to reinitialize our Colorbox.

For further information about the light box, and how you can get more from this practical plug-in, refer to the Colorbox webpage.

The result

In the end, by using a style that was automatically created by VS2010, this is the result:


Here is a bit more detailed view:



The default user for Filckr in the demo is actually an active and very nice Flickr profile. It’s my friend’s profile, mind_in_motion, so if you like nice photos, check it out. Thanks Jean Claude!  I’ll try to answer all of your questions, if any, just post a comment.

Joyful programming!


This article was initially published on CodeProject.com and if you prefer you can still consult it there. No changes to the code or text are made.

Download source code – 145 KB

One thought on “A Simple ASP.NET Flickr Application – Part 2

Leave a Reply

Your email address will not be published. Required fields are marked *