Friday, September 26, 2008

ActiveX RDP taking %100 CPU on IE6

Here's a sneaky bug we've had (credits to colleagues Corin and Leeor for solving this one), thought I'd share.

When pointing IE6 at a page with the MS RDP ActiveX control the browser would freeze and consume %100 CPU once we navigated away. It turns out that IE6 doesn't like the ActiveX control and the jqModal jQuery plugin on the same page.

jqModal includes a workaround for the IE z-index bug (a.k.a the "bleed-through" bug, fixed in IE7) by positioning an iframe right behind the dialog if using IE6. For various reasons we disabled this behavior on IE6 (and we live with the bleed-through), but the '<iframe>' was still being created inside jqModal - just not added to the document. Not creating it at all solved the bug.

Here's the (quick and dirty) patch against jqModal 2008.07.06 +r13, disabling the bleed-through fix.

Change

var s=0,H=$.jqm.hash,A=[],ie6=$.browser.msie&&($.browser.version == "6.0"),F=false,
i=$('<iframe src="javascript:false;document.write(\'\');" class="jqm"></iframe>').css({opacity:0}),
To
var s=0,H=$.jqm.hash,A=[],ie6=false,F=false,
i=$(''),

A proper diff is here.

Monday, September 15, 2008

jQuery Validation and default messages

Here is how we specify errors messages for the jQuery Validation plugin by Jörn Zaefferer: For built-in validators we modify $.validator.messages, as Jörn shows here.
$.extend($.validator.messages, {
  required: "Required",
  email: "Email not valid",
  ...
});
(we fill the actual messages in server-side processing, we don't hard-code them in the JS) For custom validators we... add custom validators.
$.validator.addMethod(
  "shouldBeGreen",
  function(value, element) {
    return this.optional(element) || /green/.test(value);
  },
  "Not green"
);
Now we can specify 'shouldBeGreen' in an input's class. That's it. Pretty simple, but it took us a while to figure it out so I hope this helps somebody.

jQuery Validation and the Google Toolbar

I am one of many happy users of the jQuery Validation plugin by Jörn Zaefferer, but I had some trouble with the Google Toolbar's auto-fill feature. When enabled, it adds a tooltip to text input fields it didn't auto-fill that says:

Your Google Toolbar can fill this in for you. Select AutoFill

One of the ways to tell the validation plugin which error message to show is by... setting the 'title' attribute, so when the Toolbar is installed all the error messages are "Your Google Toolbar can...."

Jörn has addressed the Google Toolbar issue since version 1.0, but in a way that doesn't let me use my preferred method of customizing the validation error messages.

So now there's a trac ticket including a patch with a new 'ignoreTitle' option that fixes this (if you don't use 'title' yourself).

[Edit: 26 October, 2008] Jörn has commited my patch, you can get the latest jQuery Validate plugin with Subversion:

svn co http://jqueryjs.googlecode.com/svn/trunk/plugins/validate

[Edit: 3 November, 2008] Only 'jquery.validate.js' contains the patch in svn - the minified and packed versions don't. Use the YUI Compressor or the CompressorRater to minify them yourself. Thanks to Ilan Berkner for catching this.

[Edit:21 November, 2008] Here's a direct link to the file

[Edit:8 December, 2008] Version 1.5 of the Validation plugin now contains this patch.

Monday, August 11, 2008

ASP.NET WebForms buttons and form submission

There's a problem with my previous solution to using Particletree's cool buttons - on IE7 (and only IE7) the click handler gets called twice. It turns out there's a proper way to handle form submission in ASP.NET WebForms - that lets me handle a POST the way I'd expect - and I just wasn't using it.
HTML (aspx):
<form runat="server">
   ...
   <button type="submit">...</button>
</form>
Notice that there's no 'onserverclick'.
Code-behind:
protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack)
    {
        // handle form submission
    }
}
Shame on me for not learning the basics.

Sunday, August 10, 2008

Programming Tools

In the awesome ALT.NET Israel conference we had a flipchart where people added their favorite tools.

Check it out, and try to guess what my contributions were. (Hint - if it smells of non-.NET-and-windows-land, it's probably me :)

I should have mentioned zsh explicitly as well, but I forgot.

Thursday, July 31, 2008

Cool buttons with ASP.NET WebForms

The great guys at Particletree (makers of Wufoo), wrote a great article about really cool ways to style buttons:

Rediscovering the Button Element

If you make web sites, go read that post, it's great!

The cool thing is how both buttons and regular links look exactly the same, for me this means no more buttons with

onclick="window.location.href='foo'"
just regular links that look the way I want them to.

Of course, being a noob is hard, and I wasn't sure how to create '<button>' elements that perform a postback in ASP.NET WebForms, but a little Google searching later HtmlButton comes to the rescue, and that allows me to create these cool buttons and links that look like buttons:

Cancel

And the markup couldn't be simpler:

<div class="buttons">
  <button
      runat="server"
      onserverclick="SaveButton_Click"
      type="submit">
    Save
  </button>
  <a href="#">Cancel</a>
</div>

Tuesday, June 3, 2008

Do I Know What I'm Talking About?

An nice post by Scott Hanselman on people thinking you're an expert that has led me to a great essay by Joel on Architecture Astronauts.

(Disclaimer: I'm no expert)