# Friday, 11 December 2009

In an earlier post I added character counting functionality to the ASP.Net AJAX HTML Editor with jQuery.  Soon after posting the entry I noticed that cutting and pasting text into the editor via the context menu did not change the character count immediately.  I enhanced the jQuery code in my last post to do this.

var Editor1 = '#Editor1';
var Editor1CountLimit = 50
var Editor1InfoArea = '#Info';

$(document).ready(function() {
    TrackCharacterCount(Editor1, Editor1CountLimit, Editor1InfoArea);

function TrackCharacterCount(ctl, limit, info) {
    var editor = GetEditor();
    $(editor).load(function() {

    var body = $(this).contents().find('body');
    var txt = $(body).text();
    $(info).html(txt.length); //set initial value 

    $(body).bind('cut paste', function(e) {
            setTimeout(function() {
                var txt = $(body).text();
            }, 150)
        $(this).contents().keyup(function() {
            var txt = $(this).contents().find('body').text();

function UpdateTextCounter(txt,limit,counter) {
    if (txt.length > limit)
        $(counter).html(txt.length).css("color", "red");
        $(counter).html(txt.length).css("color", "");

I added the bind code on line 17 to handle the cut and paste functionality.  I went through a couple iterations of the cut & paste functionality to count the characters correctly.  I was running into an issue where the textbox value was not being updated immediately with what was pasted.  Then I stumbled upon a nice stackoverflow answer that used a timeout to wait for the textbox to be updated.  This little jewel allowed me to simplify the code to what it is now.

I refactored the code to decrease duplication of code by creating the UpdateTextCounter function. 

I also noticed a subtle difference between IE7 and IE8 that stopped the counter from working and have corrected that in this version with a browser check.

function GetEditor() {
    if ($.browser.msie == 'true' && $.browser.version == '7.0')
        return editor = $(Editor1).contents().find('iframe').eq(1);
        return editor = $(Editor1).contents().find('iframe').eq(2);

I verified the code runs on IE7, IE8, FF 3.5.5 & Chrome 3.0.


AjaxHtmlEditorV2.zip (1.28 MB)

Read the first post.

Read the next post where I fix a bug when using a customized toolbox with the editor and find a better way to locate the IFrame that our text editor is in.

Posted 12.11.2009  #    Comments [0]  | 
# Saturday, 05 December 2009

Dynamic Data is a new project type in VS 2008.  It uses scaffolding to help code faster.  Over the past month or so I have been playing with DD and wanted to share the resources that have helped me understand and use/customize DD.

Dynamic data on codeplex: Good resource, has lots of samples on doing things beyond the basics. http://aspnet.codeplex.com/Wiki/View.aspx?title=Dynamic%20Data

Some samples include creating your own view using your own select statement.  Also in the samples is how to use Stored Procedures with DD.

Matt Berseth - http://mattberseth.com/blog/dynamic_data/

Has some nice tutorials on going beyond the basics like creating a custom meta provider that allows you to change the default way your columns are named.  For example, have the columns be Product ID instead of ProductID.

Stephen Naughton - http://csharpbits.notaclue.net/

Perhaps the best site I have found for taking DD to the next level.  Many examples of customization.  Stephen is an expert on DD in my opinion.  I used a sample from him to turn off foreign keys from showing at all for the entire application.

Craig Shoemaker also has some great examples and a book for about $10. The book isn't heavily into the underpinnings though but is worth the price for a beginner.  He also has a deep dive example which goes a little more in depth.


http://blogs.msdn.com/rickandy/archive/2009/01/08/dynamic-data-faq.aspx - Great links to resources and perhaps my second most visited site while trying to get a handle on DD.

http://www.asp.net/learn/3.5-SP1/ - video's on DD...

http://forums.asp.net/1145.aspx - forums for dynamic data....

Depending on your level of skill with Linq2SQL or Linq2EF you may want to learn more on them as well since DD sits on top of these tools.  Knowing more about these topics and extending them will also add to your arsenal for DD.

For me, I found the basics of DD to be easy to grasp but I quickly realized two things: 

  1. DD could be really great for small tasks like creating administrative pages that allow users to add / edit lookup tables, etc….
  2. Taking DD off road, aka – going beyond the basics will require a much deeper knowledge (duh).

The three items I found that are important to understand in order to take DD off road:

  • Modify / define your own metadata providers.

http://mattberseth.com/blog/2008/08/dynamic%5Fdata%5Fand%5Fcustom%5Fmetada.html - Names all columns with a space between words... Yes, you could use the DisplayName attribute but this is a sample of how to refine the basic scaffolding project.

  • Creating your own attributes.

http://csharpbits.notaclue.net/2009/04/hiding-foreign-key-column-globally-in.html - Sample of creating an attribute to hide the foreign key column for all tables.

http://csharpbits.notaclue.net/2008/10/dynamic-data-hiding-columns-in-selected.html - Sample of another attribute to hide a column but applied at the page level.

  • Create / modify the templates.

You can create your own templates and modify the existing templates to influence the UI experience.

After this, to get DD ready for the real world you can:

Tier it:


Mix it with Web forms, with MVC... http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=14473

Use AJAX and/or JQuery….  These are not DD specific modifications but likely necessary to be real world ready.

Hope this helps you on your journey!

Posted 12.05.2009  #    Comments [0]  | 
# Wednesday, 25 November 2009

I believe strongly in teams being families.  We spend eight hours a day, five days a week with each other.  A great team is able to take everyone’s ups and downs, pluses and minuses, strengths and weaknesses with dignity, respect and healthy doses of humor.  A great team is a team that isn’t all alike and embraces and remains open to diversity of ideas, backgrounds and ways of thinking even when it’s hard for them to do so.

Lindy White was one of the most unique team members I have had the pleasure to work with and go on to lead.  His candor was unmatched and so was his personality.  His tenacity and intensity for development was infectious.  He was an extremely valuable team member.  He made us all better.

Many years back we moved our website to a CMS system.  Over the years, the site grew to have around eighty content liaisons (users who could write content).  Unfortunately, strewn throughout the website were email addresses.  Our website was responsible for a large amount of email cherry picking by bots.  The team discussed how we could handle this and Lindy was given the lead to develop the solution.

As time went on, Lindy being Lindy was unsatisfied with the solution being developed and struck out to find a better way.  What he came up with was pure gold.  He wrote an HTTP Module that intercepted the outgoing HTML and converted all email addresses to a format bots could not use/read. With zero changes to our end users and next to zero maintenance on our part the web bots can no longer steal email addresses from the website.  I nominated him for an IT Pro Hero award through Windows IT Pro magazine.  Here’s the article:


Lindy knew of the award but sadly he passed away before he could see the article with his own eyes. 

It’s been a little over a year since he left us and I still think about him all the time.  Lindy, I miss you and you will always have a special place in my heart.  Thanks for the memories!

Posted 11.25.2009  #    Comments [0]  |