2012
03.04

I’m taking a break from web development topics today to talk about one of my other interests: home theater. It all started when I saw a pair of Pioneer bookshelf speakers on woot! for half the retail price. A few years back, I bought an all in one surround/DVD player/receiver. It was one of the few times that I didn’t do a lot of research before making an electronics purchase. Being somewhat of an audiophile, I was never happy with it. It worked, but the sound wasn’t crystal clear and there was very little bass. Fast forward to this past winter when I saw that pair of bookshelf speakers on woot!. Pioneer had always treated me well for car audio, so I was interested. I read tons of reviews, checked prices on Amazon.com (my online retailer of choice), and decided to make the purchase.

When the speakers arrived, I plugged them into an old receiver I had since college (not part of the all in one) and was amazed at the clarity and overall performance. I did some research and discovered that there were matching center, floor standing and subwoofer speakers from Pioneer as well. I checked out the other speakers and various receivers on Amazon and was taken back by the prices. Amazon’s prices are usually pretty good, but it was still within 10% of suggested retail. I wasn’t counting on everything showing up on woot!, nor did I want to wait that long. However, another service from the good people at woot! was able to help me out.

Deals.woot! is a community run site that lists deals found anywhere on the internet. I did a search for “Pioneer” and found a few expired results that matched my bookshelf speakers. Then I clicked the advanced search link and unchecked the “expired deals” box. Perfect! but I didn’t want to commit to checking this search on regular basis. I took my chances with the RSS feed icon in Chrome’s address bar. The feed matched my search parameters, so all I had to do was add it to my Google Reader subscriptions and I had instant Pioneer deal notifications. Over the course of the next few months, every remaining piece went on sale for 40-50% off at Newegg.

I may have gotten lucky, having the entire set of speakers plus receivers go on sale in such a short amount of time, but that doesn’t mean I won’t try deals.woot’s search results RSS feed again.

2011
06.13

The jQuery UI Message plugin is now available from NuGet. You can install it by searching for “jqueryui-message”.

Add Library Package Reference dialog

2011
06.05

I’ve been working on xVal for WebForms without xVal in the jQuery.Validate branch. So far I’ve got basic server and client side validation for most data annotations validation attributes and server side validation for IValidatableObject implementers. The only challenging part so far was understanding how to serialize the validation rules for the jQuery Validate add method.

$("#txtClientName").rules("add", {
 required: true,
 minlength: 5,
 messages: {
   required: "Client name is required.",
   minlength: "Client name must be at least 5 characters."
 }
});

I finally decided to implement JavaScriptConverter, which is used with JavaScriptSerializer. The Serialize method is what takes the Rule collection and converts it into two separate dictionaries, one for rules and one for messages. This allows the JavaScriptSerializer to properly serialize the dictionaries for the add method options parameter.

public class RulesJavaScriptConverter : JavaScriptConverter
{
    private readonly ReadOnlyCollection<Type> _supportedTypes =
        new ReadOnlyCollection<Type>(new List<Type>(new[] {typeof (RuleCollection)}));

    public override IEnumerable<Type> SupportedTypes
    {
        get { return _supportedTypes; }
    }

    public override object Deserialize(IDictionary<string, object> dictionary, Type type,
                                       JavaScriptSerializer serializer)
    {
        throw new NotSupportedException();
    }

    public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer)
    {
        return Serialize(obj as RuleCollection, serializer);
    }

    public IDictionary<string, object> Serialize(RuleCollection rules, JavaScriptSerializer serializer)
    {
        if (rules == null)
        {
            throw new ArgumentNullException("rules");
        }

        Dictionary<string, object> options =
            rules.ToDictionary<Rule, string, object>(rule => rule.Name, rule => rule.Options);
        Dictionary<string, string> messages =
            rules.ToDictionary(rule => rule.Name, rule => rule.Message);

        Dictionary<string, object> result =
            new Dictionary<string, object>(options) {{"messages", messages}};

        return result;
    }
}

And here’s how I’m using it.

StringBuilder validationOptionsScript = new StringBuilder();
validationOptionsScript.AppendFormat("$('#{0}').rules('add', ", _controlToValidateId);

JavaScriptSerializer serializer = new JavaScriptSerializer();
serializer.RegisterConverters(new[] {new RulesJavaScriptConverter()});
serializer.Serialize(rules, validationOptionsScript);

validationOptionsScript.AppendLine(");");

The next step will be figuring out validation groups. I also plan on renaming the project. My best idea so far is jQuey Validate.NET. It’s not the most creative, but it gets the point across.

2011
05.03

Based on comments I’ve received from my last xVal for WebForms post, I’ve decided on a direction. The project will keep jQuery Validation but will move away from the xVal dependency. We’ll be trying the approach outlined by Dave Ward at Encosia.

2011
03.22

I updated the jQuery UI Message plugin today. There are now methods for showhide, options and destroy. There is also a full live demo page. See more at the project page.

2011
03.14

Now that I’ve been working more and more with ASP.NET MVC, I’ve been rewriting some of my server side controls with jQuery plugins. A while back I shared my version of Janko’s popular MessageBox control. I’ve created a similar effect with a jQuery plugin based on the Highlight/Error examples on the jQuery UI Themes page.

Here’s an example:

Usage:

<div id="infoMessage">
    To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">

http://asp.net/mvc</a>.

</div>
<br />
<div id="errorMessage" style="display: none">
</div>
<script type="text/javascript">
    $(document).ready(function ()
    {
        $("#infoMessage").message();

        $("#errorMessage").message({
            type: "error",
            message: "Oops! An enexpected error has occurred.",
            dismiss: false
        });
    });
</script>

The message function accepts the following optional parameters:

  • type: “info” or “error”. Default is “info”.
  • message: “your message”. Default is the content of the element.
  • dismiss: true or false. Default is true. If true, “Click to dismiss” will be appended to the message and clicking the message will hide it.

I’ve created a plugin project at http://plugins.jquery.com/project/message and I’m hosting the source at http://code.google.com/p/jquery-message/.

2011
03.06

I’ve been neglecting xVal for WebForms for a while now, mainly because I’m not sure which direction to take it. The xVal project is now deprecated in favor of the client side validation support introduced in ASP.NET MVC 2. This is obviously a problem since xVal for WebForms is built on top of xVal.

I think there are a few directions the project could take. The more traditional WebForms approach would be to simply generate the standard System.Web.Web.UI validation controls based on a model’s DataAnnotation attributes. I’m a fan of this approach as it makes a lot of sense to WebForm developers. For example, consider the following model:

public class Booking
{
    [Required(ErrorMessage = "Client Name is required.")]
    public string ClientName { get; set; }

    [Range(1, 20, ErrorMessage = "Number of Guests must be between 1 and 20.")]
    public int NumberOfGuests { get; set; }
}

 

The generated validators would be very similar to the following:

<asp:RangeValidator ID="valNumberOfGuests" runat="server" Display="Dynamic"
ControlToValidate="txtNumberOfGuests" Type="Integer" MinimumValue="1" MaximumValue="20"
ErrorMessage="Number of Guests must be between 1 and 20."/>

<asp:RequiredFieldValidator ID="valClientName" runat="server" Display="Dynamic"
ControlToValidate="txtClientName" ErrorMessage="Client Name is required." />

 

The other option is to find a way use the ASP.NET MVC validation bits with WebForms. ASP.NET MVC 2 uses the MicrosoftAjax library, while ASP.NET MVC 3 introduced unobtrusive validation with jQuery Validate. This approach would work a lot like the current project, but it would utilize MVC instead of xVal. I have to admit I’m not thrilled about referencing System.Web.Mvc in a WebForms project.

Yet another option is to generate jQuery validation scripts from scratch, using the methods Dave Ward has suggested. I like this idea since it doesn’t put a dependency on MVC bits.

It took me a while, but after working with WebForms and trying to make validation better, i.e. more like MVC, I can’t help but think that the best option is to simply move to MVC. But xVal for WebForms can still help projects that can’t be converted to MVC. I’ve already created a branch prototyping the first, most WebForms friendly option. If you use xVal for WebForms or are interested in attribute based client and server side validation, please let me know which option you would prefer.

2011
03.01

Here’s how you can integrate IIS Express with Visual Studio 2010 without SP1. I’m taking advantage of External Tools again. There are two very simple ways to run IIS Express from the command line. The first is to pass the web project path:

You can use this by selecting your web project in the solution explorer and then running the tool.

The second way is to use a configuration file. This is for when you need something different than the default settings. For example, if you need to enable PHP. Save your applicationHost.config in the root of your project file before running this:

I’ve also attached the exported settings at the bottom of this post. You can import them from the Tools/Import and Export Settings… menu option.

Now that we can run IIS Express, we need to configure the project to use it. In the Web tab of your project settings, select Use Custom Web Server and type the Server Url that IIS Express is configured to use. The default is http://localhost:8080/.

Wasn’t that easy?

IIS Express External Tools Settings
Title : IIS Express External Tools Settings
Caption :
File name : IISExpressExternalTools.zip
Size : 1 kB
2010
12.30

I moved my blog from BlogEngine.NET to WordPress. My main reason for moving away from BE is that there just aren’t that many themes and plugins available for the latest release, 1.6.1.0. However, now that I’ve completed my transition I just saw that BE 2.0 RC is now available. And they also added Janko to their team, which leads me to believe that there will be some very cool themes available. Perhaps I should have waited?

2010
10.25

I’ve been using Visual Studio for years, but I just learned something new that’s been around since at least Visual Studio 2005. It has a built in Transact-SQL Editor that you can use to write and execute SQL queries. From what I can tell, it looks like a component of SQL Server Management Studio 2008. You can access it from the Transact-SQL option in the Data menu, which opens the editor in a new tab.