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.

2010
09.02

My company recently started a corporate wiki. We initially used ScrewTurn, an excellent open source ASP.NET application. It worked great for our department, but it wasn’t taking off for the rest of the company. Non-technical users just couldn’t get wiki markup and weren’t able to manage edits with the visual editor. So we turned to Confluence, an enterprise class commercial wiki. I won’t get into a feature comparison here. There are plenty of other sites devoted to that.

Since we had been using ScrewTurn for several months, we had a few hundred pages that we needed to migrate to Confluence. We hoped to find a utility to take care of the migration, but we were unable to find one. So in the end, I wrote my own UWC implementation for ScrewTurn.

The Confluence Universal Wiki Converter (UWC) is defined as

… a standalone application which converts pages from other wikis to Confluence. It’s also an extensible framework, allowing users with wikis that aren’t currently supported to add their own converters.

Here are the general steps I took to implement a wiki converter for ScrewTurn.

  1. Implement a Wiki Converter for ScrewTurn. I used MediaWiki’s Syntax Converter as a base since the basic wiki syntax is very similar. I also implemented a few Converter classes, UserDateConverter (requires the Confluence UDMF plugin), PagenameConverter, AttachmentsConverter, MetaDataCleaner (to remove the first three lines in ScrewTurn page files that include page name, date, and ##PAGE##).
  2. In ScrewTurn, change the page storage provider to Local Pages Provider (if its using a different provider such as SQL).
  3. Run the customized UWC implemented in step 1 and convert one namespace at a time.

You can also view my StackOverflow question and answer that inspired this post.

Confluence UWC with ScrewTurn converter source code