How to create a Carousel in a webpage

The latest fad is to create Carousels to display images, and allow for easy navigation.  I have not been able to find any .NET controls to enable you to create a Carousel on a web page.

ERROR - UNABLE TO LOAD CONTROL : ~/User controls/carousel.ascx  

So I set myself the task of generating a web page control to allow for easy, managed code, configuration of a Carousel Control in .NET

First I went on the hunt for a simple javaScript Carousel that I could use, I found a lovely Carousel by Doug Greenall, the information on his blog goes in to great detail of how the Carousel works, but this was not intention to go in to detail about the inner working of a Carousel.

So I downloaded Doug Greenall's Carousel and then went to adapt the javaScript code to create a single DLL Control that could be reused.

The end product is a small DLL that can be dragged and dropped in to your ASP.NET application or Website

Carousel.dll (21.50 kb)

The project solution was generated using Visual Studio 2008 Pro,with a Target Framework of ".NET Framework 2.0"

Carousel.zip (191.73 kb)

 

How to use the Carousel

Okay, so now I've built the Carousel Control, you now want to to know how to use it?

  • First create a new WebSite
  • Add the Carousel.dll or a project reference to your website
  • On the web page register the control (or add it to your web.config)

  • Then add the control to the page, as seen below

 

  • Next in the code behind you need to add to the CarouselDetail collection, which will add the images, links to the Carousel

 

And that is it, the more you add to the CarouselDetail collection the more items will appear on the Carousel.

Embedding javascript in an assembly

I've always been able to create a standalone DLL control that can be reused in other web applications.  I've never really found out how to embed other resources, or more to the point JavaScript files.

Until now

Here's how to embed the file:

  1. Create a js file such as carousel.js
  2. In Visual Studio, select the file in Solution Explorer and change the Build Action property to "Embedded Resource"
  3. Build the project and the carousel.js file is now part of the assembly (you don't need to distibute the js file now it's part of the assembly)

Now to get the resource out using code:

So if we have a resource named Control.carousel.js we can use the following to include it in our page:

System.IO.Stream script = Assembly.GetExecutingAssembly().GetManifestResourceStream("Control.carousel.js");
System.IO.StreamReader sr = new System.IO.StreamReader(script);
Page.ClientScript.RegisterClientScriptBlock(GetType(), "carousel", sr.ReadToEnd().ToString(), true);
sr.Close();
The above code injects the embedded file in to the page, how easy could it be?

 

Generating an Audit for LINQ

One of the tasks Jon was given was to create an Audit module for LINQ, and came across this link which seems to provide a solution.  I've not had time to go over the solution, but it appears to do a very good job at first glance.

LINQ to SQL Audit Trail 

LINQ Audit Trail v2 - DoddleAudit

Small free and replacement for Notepad

Do you still use Notepad that ships with Windows?

I did, until I found NotePad2, it's fast, it's easy to use, and more to the point it works.

I've been using it for the past 2 months, and I have not got any clue to the features, but what I like about it is it just works and is a very good replacement for the standard Windows Notepad. 

Here are the features, cribbed from the NotePad2 Website:

Customizable syntax highlighting: 

  • HTML, XML, CSS, JavaScript, VBScript, ASP, PHP, CSS, Perl/CGI
  • C/C++, C#, Java, VB, Pascal, Assembler, SQL, Python, NSIS
  • INI, REG, INF, BAT, DIFF
  • Drag & drop text editing inside and outside Notepad2
  • Basic regular expression search and replace
  • Useful word, line and block editing shortcuts
  • Rectangular selection (Alt+Mouse)
  • Brace matching, auto indent, long line marker, zoom functions
  • Support for Unicode, UTF-8, Unix and Mac text files
  • Open shell links
  • Mostly adjustable
  • Auto indentation
  • Bracket matching
  • Encoding conversion between ASCII, UTF-8 and UTF-16 formats
  • Multiple undo/redo; rectangular block selection
  • Newline conversion, between DOS (CR/LF), Unix (LF) and Mac (CR) formats 

How to Replace notepad with notepad2 in Vista?

  1. First you need to download notepad2 from here
  2. First you need to Rename Notepad2.exe to notepad.exe.
  3. Find c:\windows\notepad.exe and c:\windows\system32\notepad.exe and set the owner to ‘Administrators’, and grant Administrators full control.
  4. Using Windows Explorer, drag and drop the renamed notepad2.exe to c:\windows and c:\windows\system32.
  5. Optional replace the permissions on the new notepad.exe to Read & Execute and Read.
 
Another one to look at is Notepad++, it has a lovely set of plugins such as XML have a look at Tim Almonds post on the XML plugin

Getting Started with Silverlight

Microsoft® Silverlight™ Tools for Visual Studio 2008 SP1

 

If you going to do anything with Silverlight you're going to have to get Blend to:

Microsoft Expression Blend™ 2 Trial

Microsoft Expression Blend™ 2 Service Pack 1 

New to Silverlight?

Videos

Video Tutorials in One Place

Which game for Christmas?

I have a a wobble board for my Wii and I am looking for a game to play at Xmas, but which one?

 

My Theme made it in to the BlogEngine Themes

After my work creating the Mad Tri web site, I submitted the theme it to the BlogEngine team a few months ago and they have included it in their Theme pack, what a lovely surprise.

The BlogEngine team are going to be working hard over Christmas, with updating the BlogEngine and release a new release. more...

I too are going to the working over the Christmas on an Enhanced Newsletter and a Resource Editor to enable changes to Internationalization from the web, power to the BlogEngine 

I came from a distant planet…

LINQ to SQL and Paging

Oh how I remember those days of page through data, using a GridView controller, or any other controller, lots of coding and so easy to make a mistake.

Just take a look at http://www.unboxedsolutions.com/sean/archive/2005/12/28/818.aspx by Sean Chase, and you will see what I mean.

Things have moved on a bit since those days, and now we have LINQ it is much easier, both directly feeding from LINQ or via methods, both provide the same result.

Linq DataSource 

Here is how to enable paging directly to LINQ, by using the LinqDataSource

How easy could it be?

Linq Methods 

When it comes to generating your own method you can do this with just a little more coding and take advantange of the Linq Skip and Take methods, the sample below provides an example using a Method. 


  

To use this fully you will need to make a few changes to the webpage, as shown below:

Now that you have everything set on the page all that is left is the code behind and the methods, I am using the partial class in the example, but it does not have to be.

Code Behind

Methods 

 

To ensure that the application is Paging correctly I found running the SQL Profiler on the database made sure that only the data page was being returned and nothing else, you may want to perform your own tests too.

I have included a small application using Visual Studio 2008 and .NET 3.5, all you will need to change is the connection string settings to the NorthWind database. 

GridPerformance.zip (16.46 kb)

C# 4.0 Dynamic Language

With C# 4.0 going to include Dynamic Language programming, the reports and demos I have seen to date look very impressive.

The only main implementation and useful application was to connect to COM objects, or more to the point to Microsoft Office as this is pure COM, and always been really hard to connect and work with. 

I've also seen a demo of using the Dynamic Language to build your own .NET compiler on the fly, so building and running C# code from your own application, how cool is that?

With Dynamic Language for C#, COM should be eaiser to work with.

Microsoft have release the Dynamic Language Runtime on CodePlex so we can start to play with the new features before they are release in C# 4.0

About the author

You have probably figured out by now that my name is Bryan Avery (if not, please refer to your browser's address field).  Technology is more than a career to me - it is both a hobby and a passion.  I'm an ASP.NET/C# Developer at heart...

Month List