Thursday, May 19, 2011

Create a Paging Button for each slide in an ASP.NET AjaxControlToolkit SlideShowExtender

I had been searching for days for a way to have pretty little buttons for each slide in my slideshow extender.
Here is the always sexy nivo slider. Notice that you can have a bullet for each slide. Also, it would be cool if you could extend this guy to show tiles of the slides instead of just bullets.

 Here is what every other tutorial for the SlideShowExtender for the ASP.NET AjaxControlToolkit produced:
eeek! Try and sell that shit to a customer and see what happens.

So why not just use JQuery you might ask?

1. I don't believe in rewriting code that is already well designed. That is like wiping my ass with hard earned $100 bills.

2. The SlideShowExtender has some really cool functionality that I haven't found in the JQuery controls.

Regardless, here is how to extend the control to use paging buttons that you can easily customize to look as you please with CSS. I didn't do any pretty stuff here-- just the secret to making it work.

I am assuming that you already have your slideshow extender on the page and working as all the other 5000 tutorials on the subject show you how to do. Here is the key addition:

<div style="text-aligncenter; ">
          <div class="SlideShowMainTitle">
            <asp:Label ID="lblSlideTitle" runat="server"></asp:Label>
          <div class="SlideShowImage">
            <asp:Image ID="imgSlide" runat="server" />
          <div class="SlideShowSubTitle">            
                <asp:Label ID="lblSlideDescription" runat="server"></asp:Label>     <br />
                <asp:Repeater ID="rpPagingButtons" runat="server" OnItemDataBound="rpPagingButtons_OnItemDataBound">
                        <a ID="lbtnPager" runat="server"></a> 
            <asp:SlideShowExtender ID="slExtender" runat="server" AutoPlay="true" Loop="true" PlayInterval="3000" TargetControlID="imgSlide"
                 ImageTitleLabelID="lblSlideTitle" ImageDescriptionLabelID="lblSlideDescription" SlideShowServiceMethod="GetSlides" SlideShowServicePath="~/WebServices/SlideShowService.asmx">

Then in the code behind:

        protected void rpPagingButtons_OnItemDataBound(object sender, RepeaterItemEventArgs e)
            if (e.Item.ItemIndex > -1)
                HtmlAnchor lbtnPageLink = (HtmlAnchor)e.Item.FindControl("lbtnPager");
                if (lbtnPageLink != null)
                    string behaviorID = slExtender.BehaviorID;
                    lbtnPageLink.HRef = "javascript:$find('" + behaviorID + "')._currentIndex= " + e.Item.ItemIndex.ToString() + ";" +
                                                 " $find('" + behaviorID + "').setCurrentImage();";
                    lbtnPageLink.InnerHtml = (e.Item.ItemIndex + 1).ToString();
The key is in the href for the anchor tag. You will need to bind some data to your repeater. The dataset needs to have a row for each image in your slide show. I am assuming that you already are a decent programmer and know how to customize this to your own needs. Basically, set your bullet image in the css for the anchor tag in your repeater. You can do all of your formatting there.

Now go make daddy some bloody money.

Thursday, May 5, 2011

Clearing Up Some Space on Your Main Partition: Coping with a love for the Intel SSD, but a programmer's budget)

I recently built the best machine that I could buy parts for. This thing had everything: the ASUS P6T6 rev with an Intel I7 extreme, the NVidia three-way-sli (well, you get the picture). However, when it came down to the hard drive decision, a co-worker of mine convinced me that I just had to buy the new Intel SSD-- so I did. The problem? While Windows 7 booted in under 6 seconds--and Fedora in under 3--, I had already spent most of my budget on the "important" stuff. Thus, I bought an 80GB drive for Windows, a 40GB drive for Linux, and an eSATA 1TB external drive for all of my "non-essential" data: which is cheaper than buying a single 160GB Intel SSD. I don't know if you have priced the Intel SSDs lately, but they are EXPENSIVE! So, I think to myself, "This should be fine, I'll just store all of my music, movies, and such on the external drive." This would have been fine if the data that took up the most space was music, movies, and such. Then reality hit.

Visual Studio and all of its dependencies > 7 GB
Microsoft office and all of its dependencies >  2GB
and so on.

As a developer, I have all of these tools that I have acquired over the years, and they add up quickly.

I failed to mention that I have one other secret love. I like to, on occasion, waste my time on really fun and cool video games--I mean, we can't let that three-way-sli go to waste can we? Here is the biggest problem:

Call of Duty Black Ops (looks amazing on this machine compared to X-Box 360 b.t.w) > 12GB
Empire Total War > 16 GB

This left me with no space. Dang it! So what do you do, when you have enough friends to party like its 1999, but nowhere to put them? You store them somewhere else, and project them to where you are as holograms--except for the women, they should actually be there. Anyhow, back to the point. Since Microsoft has finally figured out that all of the *NIX s are amazing--all of them except MAC at least :)--, they have finally begun copying them. In Vista, Server 2008, and Windows 7, Microsoft finally gave Windows users an invaluable tool: The Symbolic Link. For those of you who are not familiar with UNIX derivatives, a symbolic link is a file or a directory that is stored in one place but is linked to another location. This file or directory can then be accessed as if it physically resided at the target of the link. Why is this so helpful? Well, since many software programs on Windows will not allow you to install to a location outside of the partition that the OS resides on, you previously had no choice but to install to your precious SSD space. But now .....

Move the files that are space hogs over to a folder on your external hard drive-- say F:\ProgramFiles\Steam. Then run the following as an administrator from the command line:

mklink /D "C:\Program Files (x86)\Steam" F:\ProgramFiles\Steam

Voila! The OS won't know the difference, and you get your space back for the things you get paid for. Let's just call this the tasks where it actually matters how fast the data can be accessed. By the way, I can't tell the difference in speed when I run these programs from a symbolic link.