Copying the contents of one combo box to another

Quick code tip on how to copy the contents of a combo box (HTML Select) to another. Using JQuery, of course.


I use this for forms with several date pickers, country pickers etc.

This post brought to you by - Over 10,000 Aged domains for sale!

Related posts:

  1. We Got Domain - over 10,000 aged domains for sale
  2. Cast your net wiiiide
  3. Copying cookies across domains in ASP.Net

Cool JQuery Plugins

JQuery - it really is all that & a packet of chips.

Smashing Magazine has just published 45+ New jQuery Techniques For Good User Experience and there is plenty of goodness in there.

For the JQuery plugins that I used were:

Date Picker
jCarousel (but I am thinking of replacing it with this Content Slider

This post brought to you by - Over 10,000 Aged domains for sale!

Related posts:

  1. We Got Domain - over 10,000 aged domains for sale
  2. Integrating JQuery with - A Cool Client-side Alert Box

Getting ASP.Net MVC running on IIS6

I have recently finished a new site IWantThatHotel, my first in ASP.Net MVC.

Over the next couple of weeks I will be posting code examples in VB.Net MVC (of which there are hardly any, it seems).

But first, here is a link to 2 posts that were a huge help getting the clean MVC urls running on IIS6
Deploying ASP.NET MVC to IIS 6
Several options are presented - I chose “Use a wildcard mapping for aspnet_isapi.dll” (out of the 4 options presented) because I didn’t want to alter my routes or extensions, and URL rewriting is a pain.

There is a separate post which talks about improving the performance of this method, which is worth implementing:
Disabling wildcard mapping on subdirectories

This post brought to you by - Over 10,000 Aged domains for sale!

No related posts.

Allowing special characters (forward slash, hash, asterisk etc) in ASP.Net MVC URL parameters

I’ve been getting into ASP.Net MVC a lot lately and there is plenty that is good about it.

One thing that is not good is the problems that MVC has when you have a special character (*,/,& etc) in your querystring.

Eg: Say you want to pass the param


MVC won’t like it - ‘/’ is a special character reserved as a separator for routes. But standard URL encoding it won’t work either:

MVC will still give a ‘HTTP Error 400 - Bad Request error’.

After looking around, it seems this error has been coming up a bit here and here and Phil Haack explains why standard encoding won’t work here.

One answer is to use base 64 encoding on any parameters that might contain the special characters.

        Public Function MyURLEncode(ByVal sInString As String) As String
                Dim sInStringNoSpaces As String = sInString.Replace(" ", "")
                Dim sURLEncoded As String = HttpUtility.UrlEncode(sInString)

                If sURLEncoded.Replace("+", "") = sInString.Replace(" ", "") Then
                        Return sURLEncoded
                        Return "=" & ToBase64(sInString)
                End If
        End Function

        Public Function MyURLDecode(ByVal sEncodedString As String) As String
                If sEncodedString.StartsWith("=") = True Then
                        MyURLDecode = FromBase64(Mid$(sEncodedString, 2))
                        MyURLDecode = sEncodedString.Replace("+", " ")
                End If
        End Function

        Private Function ToBase64(ByVal sInString As String) As String
                Dim btByteArray As Byte()
                Dim a As New System.Text.ASCIIEncoding()
                Dim sResult As String

                btByteArray = a.GetBytes(sInString)

                sResult = System.Convert.ToBase64String(btByteArray, 0, btByteArray.Length)
                sResult = sResult.Replace("+", "-").Replace("/", "_")
                ToBase64 = sResult
        End Function

        Private Function FromBase64(ByVal sBase64String As String) As String
                sBase64String = sBase64String.Replace("-", "+").Replace("_", "/")
                Dim obj As New ASCIIEncoding()
                FromBase64 = obj.GetString(Convert.FromBase64String(sBase64String))
        End Function

Because one of the useful things about MVC is the SEO-friendly URLs, the code doesn’t convert to Base 64 unless it is necessary.

To use these functions, here is a brief code snippet:

Public Class HotelsController
        Inherits System.Web.Mvc.Controller

        Function SelectHotelList(ByVal City As String, _
        ByVal Location As String)

                oSearch = New With {.City = MyURLEncode(City), .Location = MyURLEncode(Location)}
                Dim oDO As New RouteValueDictionary(oSearch)
                Return RedirectToAction("List", "Hotels", oDO)
        End Function

        Function List(ByVal City As String, _
                                    ByVal Location As String)

                City = MyURLDecode(City)
                Location = MyURLDecode(Location)


        End Function
End Class

Update: As Justin pointed out below, ‘/’ is a valid character in the base64 alphabet. I have had a quick read about Modified Base64 for URL which basically replaces ‘+’ and ‘/’ characters with ‘-’ and ‘_’ (I leave the padding ‘=’, but you can remove them if you want). I have updated the code with these changes, however I can’t find a test case that puts ‘/’ into the base64 encoded string - anyone know of one?

Also, the above code only encodes ASCII values, if you want to encode UNICode strings, then swap ASCIIEncoding with UnicodeEncoding.

This post brought to you by - Over 10,000 Aged domains for sale!

Related posts:

  1. SEOMoz Linkscape API wrapper in VB.Net
  2. Remove HTML tags and Javascript from pages
  3. Automate FireFox with