How to Create Your Own jQuery Plugin

15. August 2009
I just gave the following presentation at devLINK on “How to Create Your Own jQuery Plugin”. You can download the code samples and slides and investigate them in more detail. I am considering making a screencast or a blog series on the concepts described in my presentation. I find that just pos... [More]

Conference, jQuery ,


Using jQuery BlockUI Plugin with ASP.NET Input Form

15. July 2009
I was recently working on an ASP.NET WebForm project where it made sense to use a modal dialog to confirm choices, to ask for additional information, etc… I’ve used the jQuery BlockUI Plugin before and I’ve always thought it provided a good mix of nice features as well as extreme customization. Ii... [More]

ASP.NET, jQuery ,


ASP.NET MVC & jQuery Part 3: MvcContrib Grid & jQuery Plugins

8. July 2009

This is the 3rd blog post in a series taken from a recent ASP.NET MVC & jQuery presentation I gave at CodeStock. The previous blog posts are available here...

  1. Part 1: Adding jQuery Intellisense to VS 2008
  2. Part 2: Zebra Striping

MVC Contrib Grid Component

The ASP.NET MVC 1.0 Release has a lot of great things included in it, but there is another open source project called MVC Contrib that fills many gaps and compliments the core functionality.

In this blog post I want to demonstrate how you can use the MVC Contrib Grid Component in conjunction with two different jQuery plugins to provide rich functionality inside a simple and clean View.

First lets review why you might want to use the MVC Contrib Grid Component.

  • Provides a Fluent Interface
  • Discourages Logic in your View
  • Provides Reusable Grid Models
  • Customizes Grid Rendering
  • Includes a Separate Pagination Component

If the above bullet items interest you, then check out the 5 part blog series on the MVC Contrib Grid Html Helper by Jeremy Skinner.

Enough of describing the component, lets start using the MVC Contrib Grid. After adding a reference to the MvcContrib assembly to your project you can proceed adding the Grid to your View…


[More]

ASP.NET MVC, jQuery ,


ASP.NET MVC & jQuery Part 2: Zebra Striping

30. June 2009

This is the 2nd blog post in a series taken from a recent presentation I gave at CodeStock. The previous blog posts are available here...




  1. ASP.NET MVC & jQuery Part 1: Adding jQuery Intellisense to VS 2008



Probably one of the coolest things you learn (if you haven’t already) after picking up jQuery is realizing how easy it is to add zebra striping to your tables (alternating row color shading) as demonstrated in the following picture.



FireShot capture #1 - 'Scriptlet' - localhost_8080_Zebra_Scriptlet


[More]

ASP.NET MVC, jQuery ,


ASP.NET MVC & jQuery Part 1: Adding jQuery Intellisense to VS 2008

29. June 2009

As I mentioned in my previous post, I am starting a series of detailed blog entries that focus on each topic from a recent CodeStock presentation I gave entitled, “Useful jQuery tips, tricks, and plugins with ASP.NET MVC”

I’ve done several talks about jQuery over the last several months and a common question I get is how to get jQuery Intellisense into Visual Studio.

The steps to include Intellisense are actually quite straight forward and are actually easier than they were several months ago.

  1. Install Visual Studio 2008 SP1
  2. Install Visual Studio 2008 SP1 Hotfix to Support "-vsdoc.js" IntelliSense Doc Files
  3. Download jquery-1.3.2-vsdoc.js from jQuery.com
    • Note: The vsdoc.js is also included when you do a New->Project... ASP.NET MVC Web Application
  4. Include jQuery into your MasterPage

If all goes well, then you should be able to see jQuery Intellisense like this…

Intellisense

If the steps don’t give you the above results, then you might try checking out some frequently asked questions hosted on Jeff King’s (a program manager at Microsoft) website. He has a great list of gotchas that might help you getting past your particular situation.

Also, you can check out Scott Gu’s or Rick Strahl’s posts for further details of the above instructions.

[More]

ASP.NET MVC, jQuery ,


Useful jQuery Tips, Tricks, and Plugins with ASP.NET MVC

27. June 2009

I’ve given several User Group talks thus far, but this morning I gave my first conference presentation this morning at CodeStock in Knoxville, TN.

Thanks to all that came out to the talk. I hope you found some useful tips &| tricks that you can your in your near to short term development.

If you were able to attend the presentation could you please consider filling out a rating of the talk to help assist me become a better presenter?

Feel free to grab the sample code that I used during my presentation. Since I used Google Docs Presentation for my slides I am going to embed those here for your review.

Personally, I like it when people post their slides & code on their blog, but then several months down the line it is difficult to find that information again…

So, I plan to split apart the presentation into numerous detailed blog posts for those that were unable to make CodeStock and for those who would like to find the material easier in the future.

Thanks again for all of you who attended my presentation. I look forward to the rest of the conference.

[More]

ASP.NET MVC, Conference, codestock, jQuery , , ,


jQuery Resource Collection

29. May 2009

I recently started a Google Spreadsheet to include top resources for jQuery such as where to get started, great plugins, helpful tools, useful cheat sheets, quick tutorials, etc… (accessible via the tabs at the bottom of the spreadsheet)

I’ve only just begun to fill out the Spreadsheet, but I have already shown several people and told them I would post it online as a resource for them.

I hope to maintain this list not only for myself, but also to assist those that are looking for good resources. I envision more tabs being created in the near future (such as Unit Testing Frameworks, etc…)

Note: Make sure to click the tabs at the bottom on the above spreadsheet... like the Tutorials, Plugins, Tools, Cheat Sheets, and whatever else might be there in the near future :)

If you have a great resource you would like to recommend to this list, please leave a comment and I will consider adding it.


[More]

jQuery


jQuery Introduction Talk

21. May 2009

Tonight I am giving a “jQuery Introduction” presentation to the Nashville .NET User’s Group.

Time: Pizza @ 6:00pm; Presentation @ 6:30pm;

Topic: jQuery Introduction

jQuery is a JavaScript framework that makes client-side coding more simple and powerful than compared to straight JavaScript. This session will give an overview of benefits of jQuery, show how to integrate jQuery in your project, and demonstrate how easy it is to do complex things with a small amount of jQuery code.

Location:

VACO, LLC
Highwoods Plaza I (Signage out front says Aspect - Cogent)
Suite 460 (4th floor)
5410 Maryland Way
Brentwood, TN 37027

(615) 324-8226

Update: You can now download the slides from my presentation. I used the S5 web based presentation tool which allowed me to actually run jQuery examples inside the presentation.

Note: The video is still being encoded and should be live sometime this weekend. I will update this post with the video once it is available.

[More]

.NET User's Group, jQuery ,


Speaking at CodeStock 2009

19. May 2009

I am honored to have been picked as one of the CodeStock 2009 speakers for this year. Thank you to everyone who voted for my session!

The results of the voting came out yesterday and have been posted to the CodeStock website.

Useful jQuery tips, tricks, and plugins with ASP.NET MVC
Elijah Manor - ( Area: ASP.NET MVC Level: 200)

ASP.NET MVC has included the jQuery framework as part of their installation package. There are many ways in which jQuery compliments ASP.NET MVC by making the Views very simple. This session will review various tips, tricks, and plugins that demonstrate how jQuery and ASP.NET MVC work very well together.

codestock_title_09

CodeStock will be taking place June 26-27, 2009 in Knoxville, TN.

Purchase your tickets today!

You can find a list of Twitter Users that have already signed up for CodeStock on their website.

I hope to see you there! I’m sure I’ll be tweeting about my experiences :)

[More]

ASP.NET MVC, Conference, codestock, jQuery , , ,


JavaScript Unit Testing Frameworks

27. March 2009

Not only should you have unit tests for your User Interface & Middle Tier code, but you should also consider unit testing your JavaScript code.

There are several different Unit Testing frameworks made for JavaScript that you have to choose from.

Note: In future posts I will show examples of how to use each of these frameworks… as for now, this is just an introduction to the tools I’ll be covering.

Framework Description
YUI Test

YUI Test is a testing framework for browser-based JavaScript solutions. Using YUI Test, you can easily add unit testing to your JavaScript solutions. While not a direct port from any specific xUnit framework, YUI Test does derive some characteristics fromnUnit and JUnit.

JsUnit JsUnit is a Unit Testing framework for client-side (in-browser) JavaScript. It is essentially a port of JUnit to JavaScript. Also included is a platform for automating the execution of tests on multiple browsers and mutiple machines running different OSs. Its development began in January 2001.
QUnit QUnit is the unit testrunner for the jQuery project. It got promoted to a top-level project in May 2008 to make it easier to use in other projects, with focus on jQuery UI. Every plugin developer can leverage the testsuite to unit test their code.
JSSpec JSSpec is a Javascript BDD (Behavior Driven Development) framework.

Do you already use one of these frameworks? If so, which one do you prefer?

Is there another framework that you like that is better than the above listed?

Please leave a comment with your opinion :) Thanks!

[More]

JavaScript, jQuery ,


Twitter Stats using Greasemonkey & jQuery

12. March 2009

I wrote a simple Greasemonkey script that uses jQuery to read the Following, Followers, and Updates count from your Twitter Home page and displays them in the title of your Firefox tab (as seen in the image to the left).

Since I enjoy using jQuery, I tend to use this script as the starting point for several other of my custom Greasemoney scripts.

You can install the following Greasemonkey script from the userscripts.org website.




// ==UserScript==
// @name Twitter Stats
// @namespace http://zi.ma/webdev
// @description Display your Twitter Stats in the Tab Title
// @include http://twitter.com/home
// ==/UserScript==

//BEGIN - Load jQueryhttp://is.gd/j6G
var GM_JQ = document.createElement('script');
GM_JQ.src = 'http://jquery.com/src/jquery-latest.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);

function GM_wait() {
if (typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(GM_wait,100); }
else { $ = unsafeWindow.jQuery; letsJQuery(); }
}
GM_wait();
//END - Load jQuery http://is.gd/j6G

// All your GM code must be inside this function
function letsJQuery() {
unsafeWindow.console.log('BEGIN letsJQuery');

var followers = $("#follower_count").html();
var following = $("#following_count").html();
var updates = $("#update_count").html();
document.title = 'Twitter / Ing: ' + $.trim(following) + '; Ers: ' + $.trim(followers);

unsafeWindow.console.log('END letsJQuery');
}

unsafeWindow.alert = function alert(message) {
//do nothing
};

[More]

Greasemonkey, Twitter, jQuery , ,


Watercolor Date Night Turned jQuery

21. February 2009

My wife and I went on a long overdue date night. We first went out to eat and then came back home after the kids were in bed to do some relaxing watercolor painting.

We had been brainstorming for quite some time about the subject of our painting... and then I came upon the above "jQuery Rocks" idea.

Although I enjoyed adding some tech to my painting, I am thinking next time we do this activity, I will choose to paint a landscape or something less geeky :)

A friend of mine suggested that I put it up on eBay... I wonder if anyone would even bid on it!?!

[More]

jQuery


Mini jQuery Lab

13. February 2009
Yesterday, I ran across an interesting blog entry written by Jeffery. The title and images caught my eye, but I had a hard time understanding the Chinese. The article talked about a "Mini jQuery Lab" and had pictures showing a cool playground webpage mixing CSS, HTML, and jQuery!

I sent the URL through Google Translate to try to find where I could download the tool, but I still had difficulty figuring out the translation. Finally, I left a comment and the author walked me through what to do.

Basically, I just download the jQueryDemo5.zip from the bottom of a MSDN article. Inside the zip file was the Mini jQuery Lab. I extracted just the Mini jQuery Lab part of the zip, and hosted it on my website for your download.

So, I thought I'd play around with the tool for a little while. I ended up making a real simple jQuery AJAX call to retrieve my latest tweets from Twitter and display them inside of an ordered list.

At any time you can click the 'View HTML Source' link at the top of the webpage to view a complete page with all your CSS, HTML, and jQuery showing inside a SyntaxHighlighter pre tag.

Here is the code if you are interested in what I was playing around with...








List of My Tweets





I hope you find this a useful tool. I can see it very handy when playing around with small new tricks or showing some things off during a presentation.

[More]

Twitter, jQuery ,


Tech Twitterings via jQuery & Twitter

20. November 2008

Several weeks ago, I decided to start a weekly blog entry compiling a list of my technical tweets from Twitter. After the second week, I noticed that it was taking me much too long to compile the list, so I decided to create a tool to make it easier.

My current solution involves several Firefox add-ons, jQuery, and Twitter. Eventually, it would probably be much easier if I used the Twitter APIs directly, but for now I have found this solution to be a fun learning exercise :)

Steps to Create the Tech Twitterings Entry
  1. Search for my technical (#tech) tweets from Twitter
  2. Use the Firefox AutoPager add-on to automatically load the next several pages to capture all the tweets from the last week.
  3. Use the Firefox Greasemonkey add-on and run the Load jQuery Library script to load the jQuery library onto the Twitter search page
Load jQuery Library

// ==UserScript==
// @name Load jQuery Library
// @namespace http://webdevdotnet.blogspot.com
// @include http://search.twitter.com/*
// ==/UserScript==

//Code taken from http://internetducttape.com/2008/05/08/greasemonkey-ninja-jquery/
var GM_JQ = document.createElement('script');
GM_JQ.src = 'http://jquery.com/src/jquery-latest.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);

function GM_wait() {
if (typeof unsafeWindow.jQuery == 'undefined') {
window.setTimeout(GM_wait,100);
} else {
$ = unsafeWindow.jQuery; letsJQuery();
}
}
GM_wait();

function letsJQuery() {
unsafeWindow.console.log('The jQuery Library has been loaded');
}
  1. Use the Firefox Firebug add-on and use it's console (F12) to run the jQuery Twitter Script
jQuery Twitter Script

$('li.result .msg .msgtxt .expand').remove();
var categories = new Array();
var categoryKeys = new Array();
$('li.result .msg .msgtxt').each(function(i,tweet) {
var tweetText = $(tweet).text();
var regularExpression = new RegExp('.*#tech.*(#\\w+).*', 'gi');
var matches = regularExpression.exec(tweetText);
if (matches != null) {
var match = matches[1];
if (categories[match] == null ) {
categories[match] = new Array();
categoryKeys.push(match);
}
categories[match].push(tweetText);
}
});
for (var i = 0; i < categoryKeys.length; ++i) {
var categoryKey = categoryKeys[i];
console.log('

' + categoryKey + '

    ');
    var category = categories[categoryKey];
    for (var j = 0; j < category.length; ++j) {
    console.log('
  • ' + category[j] + '
  • ');
    }
    console.log('
');
}
  1. Copy & Paste the contents from the console into Blogger
  2. Surround the auto-generated HTML content in a div and prepend the JavaScript to convert Text to Hyperlinks.
Text to Hyperlink JavaScript


[More]

Twitter, jQuery ,


jQuery Flexigrid Using C# 3.0 (.NET 3.5) & LINQ

23. July 2008

When I developed my first ASP.NET MVC application, I was a little disappointed with my options for a rich grid. I initially used the grid that is part of the MVCContrib project, but it is pretty simple and there aren’t many features out of the box.

I was very pleased with the code of my MVC application, but the presentation was so 1990's. With all of this new technology I thought the presentation deserved something snappy. That is when I found Flexigrid.

As I mentioned in my last blog entry, I started to use jQuery. To my joy, Flexigrid is a jQuery plugin! Flexigrid uses jQuery to asynchronously populate the contents of the grid using either XML or JSON input.

The following is an example of what the grid looks like. It contains features to sort, page, search, move columns, resize, etc…

flexigridExample

The User Interface portion was pretty straightforward to put together. You just need to define your columns, the data source, and some additional parameters (such as: search terms, size, etc…).
   1: "ctlFlex" style="display: none">
   2: 

I wanted to use this opportunity to try out some new features of .NET 3.5, so I wanted to incorporate LINQ and JSON serialization.

To do this, I needed to setup some classes that the Flexigrid will recognize once serialized. Here is what I came up with.

   1: public class FlexigridViewData
   2: {
   3:     public int page;
   4:     public int total;
   5:     public List rows = new List();
   6: }
   7:  
   8: public class FlexigridRow
   9: {
  10:     public long id;
  11:     public List<string> cell;
  12: }

Now is the part where the fun begins. I had already retrieved the content I needed from the Middle Tier. I use LINQ to query the generic list to obtain the correct page subset and then use a helper extension method to serialize the contents to JSON.

   1: public void Page_Load()
   2: {
   3:     Response.Clear();
   4:     Response.ContentType = "text/x-json";
   5:     Response.Write(GetPagedContent());
   6:     Response.Flush();
   7:     Response.End();
   8: }
   9:  
  10: private string GetPagedContent()
  11: {
  12:     var pageIndex = Convert.ToInt32(Request.Params["page"]);
  13:     var itemsPerPage = Convert.ToInt32(Request.Params["rp"]);
  14:     var sortName = Request.Params["sortname"];
  15:     var sortOrder = Request.Params["sortorder"];
  16:     var query = Request.Params["query"];
  17:  
  18:     IEnumerable pagedContacts;
  19:     if (string.IsNullOrEmpty(query))
  20:     {
  21:         pagedContacts = sortOrder.Equals("asc") ?
  22:             Contacts.OrderBy(contact => contact.GetPropertyValue(sortName)) :
  23:             Contacts.OrderByDescending(contact => contact.GetPropertyValue(sortName));                
  24:     }
  25:     else
  26:     {
  27:         Funcbool> whereClause = (contact => contact.GetPropertyValue<string>(sortName).Contains(query));
  28:         pagedContacts = sortOrder.Equals("asc", StringComparison.CurrentCultureIgnoreCase) ?
  29:             Contacts.Where(whereClause).OrderByDescending(contact => contact.GetPropertyValue(sortName)) :
  30:             Contacts.Where(whereClause).OrderBy(contact => contact.GetPropertyValue(sortName));
  31:     }
  32:     int count = pagedContacts.Count();
  33:     pagedContacts = pagedContacts.Skip((pageIndex - 1) * itemsPerPage).Take(itemsPerPage);
  34:  
  35:     const string imageLinkFormat = @""{0}"">"{1}"" border=""0"" />";
  36:     const string imageFormat = @""{0}"" border=""0"" />";
  37:     var flexigrid = new FlexigridViewData {page = pageIndex, total = count};
  38:     foreach (var contact in pagedContacts)
  39:     {
  40:         flexigrid.rows.Add(new FlexigridRow
  41:         {
  42:             id = contact.ID,
  43:             cell = new List<string> 
  44:             { 
  45:                 string.Format(imageLinkFormat, ResolveUrl("~/Contact.mvc/Detail/" + contact.ID), 
  46:                 ResolveUrl("~/Images/Detail.gif")), 
  47:                 contact.ID.ToString(), 
  48:                 contact.FirstName, 
  49:                 contact.LastName, 
  50:                 contact.DateOfBirth.ToShortDateString(), 
  51:             }
  52:         });
  53:     }
  54:  
  55:     return flexigrid.ToJson();    
  56: }

Here are some helper extension methods that I used to complete the above code snippets.

   1: public static class JsonHelper
   2: {
   3:     public static string ToJson(this object obj)
   4:     {
   5:         var serializer = new JavaScriptSerializer();
   6:  
   7:         return serializer.Serialize( obj );
   8:     }
   9:  
  10:     public static string ToJson(this object obj, int recursionDepth)
  11:     {
  12:         var serializer = new JavaScriptSerializer();
  13:  
  14:         serializer.RecursionLimit = recursionDepth;
  15:  
  16:         return serializer.Serialize( obj );
  17:     }
  18: }

   1: public static T GetPropertyValue(this object component, string propertyName)
   2: {
   3:     return (T) TypeDescriptor.GetProperties(component)[propertyName].GetValue(component);
   4: }

As a side note, I did have to dive into the JavaScript and fix two issues that I came across, but other than that it works like a charm.

I would prefer if the developer of the product had a better system of tracking bugs and maintaining a forum, but in the meantime what is setup is sufficient.

[More]

Tools, AJAX, ASP.NET MVC, jQuery , , ,


Olark Livehelp