<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www.componentart.com/BLOGS/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Jovan&amp;#039;s Blog</title><subtitle type="html">Ramblings of a web control developer.</subtitle><id>http://www.componentart.com/BLOGS/jovan/atom.aspx</id><link rel="alternate" type="text/html" href="http://www.componentart.com/BLOGS/jovan/default.aspx" /><link rel="self" type="application/atom+xml" href="http://www.componentart.com/BLOGS/jovan/atom.aspx" /><generator uri="http://communityserver.org" version="2.1.61019.2">Community Server</generator><updated>2006-11-28T23:28:00Z</updated><entry><title>MaskedInput Transform Intellisense</title><link rel="alternate" type="text/html" href="http://www.componentart.com/BLOGS/jovan/archive/2008/10/27/maskedinput-transform-intellisense.aspx" /><id>http://www.componentart.com/BLOGS/jovan/archive/2008/10/27/maskedinput-transform-intellisense.aspx</id><published>2008-10-27T14:06:00Z</published><updated>2008-10-27T14:06:00Z</updated><content type="html">&lt;br /&gt;MaskedInput class&amp;#39;s Transform property that I described in depth in a few preceding blog posts presented us with an interesting design dilemma. At first it seemed like it should be a typical enumeration property, with one value for each Transform type. However, since the architecture allowed new Transform types to be added in a number of different ways (see the previous blog posts), the enum turned out to be too stifling. For that reason, we opted for a string instead.&lt;br /&gt;&lt;br /&gt;However, we still wanted to offer some Intellisense, to give the developer a hint at the values he would most likely want to use. We did it by placing the TypeConverterAttribute on the Transform property:&lt;br /&gt;&lt;pre style="font-family:courier new;background-color:#e2e2e2;border:#a0a0a0 1px solid;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;sealed&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; MaskedInput : BaseInput
{
  ...
  [TypeConverter(&lt;span style="color:#0000ff;"&gt;typeof&lt;/span&gt;(MaskedInputTransformConverter))]
  &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; Transform
  {
    &lt;span style="color:#0000ff;"&gt;get&lt;/span&gt; {...}
    &lt;span style="color:#0000ff;"&gt;set&lt;/span&gt; {...}
  }
  ...
}
&lt;/pre&gt;&lt;br /&gt;The implementation of MaskedInputTransformConverter is very simple:&lt;br /&gt;&lt;pre style="font-family:courier new;background-color:#e2e2e2;border:#a0a0a0 1px solid;"&gt;&lt;span style="color:#808080;"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span style="color:#808080;"&gt;/// Provides Visual Studio intellisense for Transform property.&lt;/span&gt;
&lt;span style="color:#808080;"&gt;/// The list of StandardValues here corresponds to the properties of client-side ComponentArt_MaskedInput_Transforms object.&lt;/span&gt;
&lt;span style="color:#808080;"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; MaskedInputTransformConverter : TypeConverter
{
  &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;[] StandardValues =
  {
    &amp;quot;&lt;span style="color:#8b0000;"&gt;empty&lt;/span&gt;&amp;quot;, 
    &amp;quot;&lt;span style="color:#8b0000;"&gt;CreditCard_VisaMasterCard&lt;/span&gt;&amp;quot;,
    &amp;quot;&lt;span style="color:#8b0000;"&gt;CreditCard_AmEx&lt;/span&gt;&amp;quot;,
    &amp;quot;&lt;span style="color:#8b0000;"&gt;Telephone_NorthAmerica&lt;/span&gt;&amp;quot;,
    &amp;quot;&lt;span style="color:#8b0000;"&gt;ZipCode&lt;/span&gt;&amp;quot;,
    &amp;quot;&lt;span style="color:#8b0000;"&gt;PostalCode&lt;/span&gt;&amp;quot;,
    &amp;quot;&lt;span style="color:#8b0000;"&gt;PostalCode_Australia&lt;/span&gt;&amp;quot;,
    &amp;quot;&lt;span style="color:#8b0000;"&gt;EmailAddress&lt;/span&gt;&amp;quot;
  };
  &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;override&lt;/span&gt; StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
  {
    &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; StandardValuesCollection(StandardValues);
  }
  &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;override&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;bool&lt;/span&gt; GetStandardValuesSupported(ITypeDescriptorContext context)
  {
    &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;true&lt;/span&gt;;
  }
}&lt;/pre&gt;&lt;br /&gt;This works really well in ASPX Intellisense, popping up the list of standard values, without forcing you to use one of them - exactly the behaviour we needed. The Intellisense also works for the Properties pane. Unfortunately it does not work in the CodeBehind files, and I don&amp;rsquo;t think there is a way to implement it there.&lt;br /&gt;&lt;br /&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.componentart.com/BLOGS/jovan/archive/2008/10/27/maskedinput-transform-intellisense.aspx&amp;amp;;subject=MaskedInput+Transform+Intellisense" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2008/10/27/maskedinput-transform-intellisense.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.componentart.com/BLOGS/jovan/archive/2008/10/27/maskedinput-transform-intellisense.aspx&amp;amp;;title=MaskedInput+Transform+Intellisense" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2008/10/27/maskedinput-transform-intellisense.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.componentart.com/BLOGS/jovan/archive/2008/10/27/maskedinput-transform-intellisense.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2008/10/27/maskedinput-transform-intellisense.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.componentart.com/BLOGS/jovan/archive/2008/10/27/maskedinput-transform-intellisense.aspx&amp;amp;title=MaskedInput+Transform+Intellisense" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2008/10/27/maskedinput-transform-intellisense.aspx"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.componentart.com/BLOGS/aggbug.aspx?PostID=24624" width="1" height="1"&gt;</content><author><name>Jovan</name><uri>http://www.componentart.com/BLOGS/members/Jovan.aspx</uri></author><category term="ASP.NET AJAX" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/ASP.NET+AJAX/default.aspx" /><category term="C#" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/C_2300_/default.aspx" /><category term="Visual Studio" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/Visual+Studio/default.aspx" /><category term="ComponentArt Web.UI" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/ComponentArt+Web.UI/default.aspx" /><category term="Input" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/Input/default.aspx" /><category term="MaskedInput" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/MaskedInput/default.aspx" /></entry><entry><title>Building in new MaskedInput Transforms</title><link rel="alternate" type="text/html" href="http://www.componentart.com/BLOGS/jovan/archive/2008/10/24/building-in-new-maskedinput-transforms.aspx" /><id>http://www.componentart.com/BLOGS/jovan/archive/2008/10/24/building-in-new-maskedinput-transforms.aspx</id><published>2008-10-24T14:05:00Z</published><updated>2008-10-24T14:05:00Z</updated><content type="html">&lt;br /&gt;In the previous post I explained how you can customize the behaviour of MaskedInput&amp;rsquo;s Transforms. That should probably cover all your needs. However, MaskedInput&amp;rsquo;s architecture does allow for one more way to customize transforms. You can actually build in your own.&lt;br /&gt;&lt;br /&gt;As you can see from the MaskedInput_Transforms.js file attached in the previous post, all the built-in transforms are contained in a global JavaScript object named ComponentArt_MaskedInput_Transforms, indexed by Transform name. So building in a new Transform is as easy as adding another property to ComponentArt_MaskedInput_Transforms. You can do that in a few ways:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;You can completely redefine the object ComponentArt_MaskedInput_Transforms: &lt;pre style="font-family:courier new;background-color:#e2e2e2;border:#a0a0a0 1px solid;"&gt; &amp;lt;script type=&amp;quot;&lt;span style="color:#8b0000;"&gt;text/javascript&lt;/span&gt;&amp;quot;&amp;gt;
   &lt;span style="color:#0000ff;"&gt;window&lt;/span&gt;.ComponentArt_MaskedInput_Transforms =
   {
     &amp;#39;UpperCaseInput&amp;#39;:
     {
       &amp;#39;validate&amp;#39;: &lt;span style="color:#0000ff;"&gt;function&lt;/span&gt;(maskedInput) {&lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;true&lt;/span&gt;;},
       &amp;#39;unmask&amp;#39;: &lt;span style="color:#0000ff;"&gt;function&lt;/span&gt;(maskedInput) {&lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; maskedInput.masked.value.toUpperCase();},
       &amp;#39;mask&amp;#39;: &lt;span style="color:#0000ff;"&gt;function&lt;/span&gt;(maskedInput) {&lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; maskedInput.unmasked.value.toUpperCase();}
     }
   }
 &amp;lt;/script&amp;gt;
 &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#c71585;"&gt;ComponentArt&lt;/span&gt;:&lt;span style="color:#800000;"&gt;MaskedInput&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;runat&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;ID&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;MaskedInput1&amp;quot;&lt;/span&gt;
   &lt;span style="color:#ff0000;"&gt;Transform&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;UpperCaseInput&amp;quot;&lt;/span&gt;
 &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;br /&gt;Keep in mind that because you are overwriting ComponentArt_MaskedInput_Transforms, the built-in transforms will no longer work.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;A less drastic solution is to just add your new Transform to the existing ones:&lt;br /&gt;&lt;pre style="font-family:courier new;background-color:#e2e2e2;border:#a0a0a0 1px solid;"&gt; &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#c71585;"&gt;ComponentArt&lt;/span&gt;:&lt;span style="color:#800000;"&gt;MaskedInput&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;runat&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;ID&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;MyMaskedInput&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;
 &amp;lt;script type=&amp;quot;&lt;span style="color:#8b0000;"&gt;text/javascript&lt;/span&gt;&amp;quot;&amp;gt;
   &lt;span style="color:#0000ff;"&gt;window&lt;/span&gt;.ComponentArt_MaskedInput_Transforms.UpperCaseInput =
   {
     &amp;#39;validate&amp;#39;: &lt;span style="color:#0000ff;"&gt;function&lt;/span&gt;(maskedInput) {&lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;true&lt;/span&gt;;},
     &amp;#39;unmask&amp;#39;: &lt;span style="color:#0000ff;"&gt;function&lt;/span&gt;(maskedInput) {&lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; maskedInput.masked.value.toUpperCase();},
     &amp;#39;mask&amp;#39;: &lt;span style="color:#0000ff;"&gt;function&lt;/span&gt;(maskedInput) {&lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; maskedInput.unmasked.value.toUpperCase();}
   }
   &lt;span style="color:#0000ff;"&gt;window&lt;/span&gt;.MyMaskedInput.set_transform(&amp;#39;UpperCaseInput&amp;#39;);
 &amp;lt;/script&amp;gt;
&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;If you have a source code license and are compiling your own custom builds, you can easily add your transforms directly to the JavaScript file. They will then work just like the original built-in transforms.&lt;br /&gt;If you are doing this, you may also want to extend MaskedInput Transform Intellisense, as described in the next blog post. &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.componentart.com/BLOGS/jovan/archive/2008/10/24/building-in-new-maskedinput-transforms.aspx&amp;amp;;subject=Building+in+new+MaskedInput+Transforms" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2008/10/24/building-in-new-maskedinput-transforms.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.componentart.com/BLOGS/jovan/archive/2008/10/24/building-in-new-maskedinput-transforms.aspx&amp;amp;;title=Building+in+new+MaskedInput+Transforms" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2008/10/24/building-in-new-maskedinput-transforms.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.componentart.com/BLOGS/jovan/archive/2008/10/24/building-in-new-maskedinput-transforms.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2008/10/24/building-in-new-maskedinput-transforms.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.componentart.com/BLOGS/jovan/archive/2008/10/24/building-in-new-maskedinput-transforms.aspx&amp;amp;title=Building+in+new+MaskedInput+Transforms" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2008/10/24/building-in-new-maskedinput-transforms.aspx"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.componentart.com/BLOGS/aggbug.aspx?PostID=24621" width="1" height="1"&gt;</content><author><name>Jovan</name><uri>http://www.componentart.com/BLOGS/members/Jovan.aspx</uri></author><category term="JavaScript" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/JavaScript/default.aspx" /><category term="ComponentArt Web.UI" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/ComponentArt+Web.UI/default.aspx" /><category term="Input" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/Input/default.aspx" /><category term="MaskedInput" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/MaskedInput/default.aspx" /></entry><entry><title>Customizing MaskedInput Transforms</title><link rel="alternate" type="text/html" href="http://www.componentart.com/BLOGS/jovan/archive/2008/10/23/customizing-maskedinput-transforms.aspx" /><id>http://www.componentart.com/BLOGS/jovan/archive/2008/10/23/customizing-maskedinput-transforms.aspx</id><published>2008-10-23T13:30:00Z</published><updated>2008-10-23T13:30:00Z</updated><content type="html">&lt;br /&gt;In this blog post I will assume that you understand how MaskedInput Transforms function. It was explained in the &lt;a href="http://www.componentart.com/BLOGS/jovan/archive/2008/10/22/maskedinput-transform-functionality.aspx"&gt;previous blog post&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Here is the list of currently implemented transforms:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;CreditCard_VisaMasterCard&lt;/strong&gt; - Visa or MasterCard credit card number.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;CreditCard_AmEx&lt;/strong&gt; - American Express credit card number.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Telephone_NorthAmerica&lt;/strong&gt; - North American telephone number.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;ZipCode&lt;/strong&gt; - American ZIP code.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;PostalCode&lt;/strong&gt; - Canadian postal code.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;PostalCode_Australia&lt;/strong&gt; - Australian postal code.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;EmailAddress&lt;/strong&gt; - e-mail address.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;empty&lt;/strong&gt; - accepts all inputs.&lt;/li&gt;&lt;/ul&gt;empty Transform is a special case. It accepts all inputs, and it doesn&amp;#39;t mask or unmask them. Here is how it looks in code: &lt;pre style="font-family:courier new;background-color:#e2e2e2;border:#a0a0a0 1px solid;"&gt; &lt;span style="color:#800000;"&gt;&amp;#39;empty&amp;#39;&lt;/span&gt;:
 {
   &lt;span style="color:#800000;"&gt;&amp;#39;validate&amp;#39;&lt;/span&gt;: &lt;span style="color:#0000ff;"&gt;function&lt;/span&gt;(maskedInput)
   {
     &lt;span style="color:#008000;"&gt;// Accept all input:&lt;/span&gt;
     &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;true&lt;/span&gt;;
   },
   &lt;span style="color:#800000;"&gt;&amp;#39;unmask&amp;#39;&lt;/span&gt;: &lt;span style="color:#0000ff;"&gt;function&lt;/span&gt;(maskedInput)
   {
     &lt;span style="color:#008000;"&gt;// Just pass on the edited displayed text:&lt;/span&gt;
     &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; maskedInput.masked.value;
   },
   &lt;span style="color:#800000;"&gt;&amp;#39;mask&amp;#39;&lt;/span&gt;: &lt;span style="color:#0000ff;"&gt;function&lt;/span&gt;(maskedInput)
   {
     &lt;span style="color:#008000;"&gt;// Just pass on the unmasked value:&lt;/span&gt;
     &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; maskedInput.unmasked.value;
   }
 }&lt;/pre&gt;&lt;br /&gt;There is not enough space in this blog post to show the code of the rest of the Transforms, but I made &lt;a href="http://blogs.componentart.com/jovan/files/MaskedInput_Transforms.zip"&gt;the source code file&lt;/a&gt; available for download.&lt;br /&gt;&lt;br /&gt;Ideally the available transforms will be enough for your requirements. New transforms are very easy to build in, so please don&amp;#39;t hesitate to send in your suggestions.&lt;br /&gt;&lt;br /&gt;However, for those times when your requirements cannot be met by the built-in transforms, there are a number of ways to customize the MaskedInput.&lt;br /&gt;&lt;br /&gt;In addition to Transform, MaskedInput exposes three more server-side properties: &lt;strong&gt;TransformValidate&lt;/strong&gt;, &lt;strong&gt;TransformUnmask&lt;/strong&gt;, and &lt;strong&gt;TransformMask&lt;/strong&gt;. These allow you to override the behaviour of any of the three transform functions. For example, to make the Visa card transform featured in the previous blog post mask with dashes instead of masking with spaces, you can do something like this: &lt;pre style="font-family:courier new;background-color:#e2e2e2;border:#a0a0a0 1px solid;"&gt; &amp;lt;script type=&amp;quot;&lt;span style="color:#8b0000;"&gt;text/javascript&lt;/span&gt;&amp;quot;&amp;gt;
   &lt;span style="color:#0000ff;"&gt;function&lt;/span&gt; maskVisaWithDashes(maskedInput)
   {
     &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; maskedInput.unmasked.value.replace(/^(\d{4})(\d{4})(\d{4})(\d{4})$/, &amp;#39;$1-$2-$3-$4&amp;#39;);
   }
 &amp;lt;/script&amp;gt;
 &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#c71585;"&gt;ComponentArt&lt;/span&gt;:&lt;span style="color:#800000;"&gt;MaskedInput&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;runat&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;ID&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;MyMaskedInput&amp;quot;&lt;/span&gt;
   &lt;span style="color:#ff0000;"&gt;Transform&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;CreditCard_VisaMasterCard&amp;quot;&lt;/span&gt;
   &lt;span style="color:#ff0000;"&gt;TransformMask&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;maskVisaWithDashes&amp;quot;&lt;/span&gt;
 &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;This allows you to fully override any of the Transform&amp;#39;s functions. Note that you can also leave the Transform property blank. In that case, the control defaults to the empty transform.&lt;br /&gt;&lt;br /&gt;In the next blog post, I will introduce another more integrated way to add a new Transform.&lt;br /&gt;&lt;br /&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.componentart.com/BLOGS/jovan/archive/2008/10/23/customizing-maskedinput-transforms.aspx&amp;amp;;subject=Customizing+MaskedInput+Transforms" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2008/10/23/customizing-maskedinput-transforms.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.componentart.com/BLOGS/jovan/archive/2008/10/23/customizing-maskedinput-transforms.aspx&amp;amp;;title=Customizing+MaskedInput+Transforms" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2008/10/23/customizing-maskedinput-transforms.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.componentart.com/BLOGS/jovan/archive/2008/10/23/customizing-maskedinput-transforms.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2008/10/23/customizing-maskedinput-transforms.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.componentart.com/BLOGS/jovan/archive/2008/10/23/customizing-maskedinput-transforms.aspx&amp;amp;title=Customizing+MaskedInput+Transforms" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2008/10/23/customizing-maskedinput-transforms.aspx"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.componentart.com/BLOGS/aggbug.aspx?PostID=24618" width="1" height="1"&gt;</content><author><name>Jovan</name><uri>http://www.componentart.com/BLOGS/members/Jovan.aspx</uri></author><category term="JavaScript" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/JavaScript/default.aspx" /><category term="ComponentArt Web.UI" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/ComponentArt+Web.UI/default.aspx" /><category term="Input" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/Input/default.aspx" /><category term="MaskedInput" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/MaskedInput/default.aspx" /></entry><entry><title>MaskedInput Transform functionality</title><link rel="alternate" type="text/html" href="http://www.componentart.com/BLOGS/jovan/archive/2008/10/22/maskedinput-transform-functionality.aspx" /><id>http://www.componentart.com/BLOGS/jovan/archive/2008/10/22/maskedinput-transform-functionality.aspx</id><published>2008-10-22T14:06:00Z</published><updated>2008-10-22T14:06:00Z</updated><content type="html">&lt;br /&gt;The format of the masked input is fully defined by the &amp;quot;Transform&amp;quot; it uses.&lt;br /&gt;&lt;br /&gt;A Transform is a client-side JavaScript object containing just three functions:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;&lt;strong&gt;validate&lt;/strong&gt; &amp;ndash; A function that takes a look at what the user just typed into the masked input box, and returns a boolean value: true if text is valid, false if it isn&amp;#39;t.&lt;br /&gt;For example, if the transform is used to accept a Visa card number, and the user types in &amp;quot;4506/00020002-0002&amp;quot;, this function returns true. (It just makes sure that there are exactly 16 digits.) If the user types in &amp;quot;2008-10-14&amp;quot;, the function returns false.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;unmask&lt;/strong&gt; &amp;ndash; A function that takes a look at what the user has just typed into the input box, and &amp;quot;unmasks&amp;quot; it. Typically, this means that the text is cleaned of formatting, leaving behind just the raw data. Unmask gets called even when validate does not return true, so it should not assume that the masked text it is working on is valid.&lt;br /&gt;In our example, if the user typed in &amp;quot;4506/00020002-0002&amp;quot;, this function will return &amp;quot;4506000200020002&amp;quot;.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;mask&lt;/strong&gt; &amp;ndash; A function that takes a look at the raw, clean data, and &amp;quot;masks&amp;quot; it: formats it for display.&lt;br /&gt;With our raw data being &amp;quot;4506000200020002&amp;quot;, this function will return &amp;quot;4506 0002 0002 0002&amp;quot;.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;Each of these methods takes only one argument: the reference to the client-side MaskedInput JavaScript object. The function can then easily use this object to get any other information it needs. For example, here is the entire code of the Visa card transform:&lt;br /&gt;&lt;pre style="font-family:courier new;background-color:#e2e2e2;border:#a0a0a0 1px solid;"&gt; &lt;span style="color:#800000;"&gt;&amp;#39;CreditCard_VisaMasterCard&amp;#39;&lt;/span&gt;:
 {
   &lt;span style="color:#800000;"&gt;&amp;#39;validate&amp;#39;&lt;/span&gt;: &lt;span style="color:#0000ff;"&gt;function&lt;/span&gt;(maskedInput)
   {
     &lt;span style="color:#008000;"&gt;// Ensure the unmasked edited text has exactly 16 digits:&lt;/span&gt;
     &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.unmask(maskedInput).&lt;span style="color:#0000ff;"&gt;length&lt;/span&gt; === 16;
   },
   &lt;span style="color:#800000;"&gt;&amp;#39;unmask&amp;#39;&lt;/span&gt;: &lt;span style="color:#0000ff;"&gt;function&lt;/span&gt;(maskedInput)
   {
     &lt;span style="color:#008000;"&gt;// Simply remove all the non-digits from the displayed text:&lt;/span&gt;
     &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; maskedInput.masked.value.replace(&lt;span style="color:#800000;"&gt;/[^\d]/g&lt;/span&gt;, &lt;span style="color:#800000;"&gt;&amp;#39;&amp;#39;&lt;/span&gt;);
   },
   &lt;span style="color:#800000;"&gt;&amp;#39;mask&amp;#39;&lt;/span&gt;: &lt;span style="color:#0000ff;"&gt;function&lt;/span&gt;(maskedInput)
   {
     &lt;span style="color:#008000;"&gt;// Insert spaces between four-digit groups:&lt;/span&gt;
     &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; maskedInput.unmasked.value.replace(&lt;span style="color:#800000;"&gt;/^(\d{4})(\d{4})(\d{4})(\d{4})$/&lt;/span&gt;, &lt;span style="color:#800000;"&gt;&amp;#39;$1 $2 $3 $4&amp;#39;&lt;/span&gt;);
   }
 }&lt;/pre&gt;&lt;br /&gt;Two often used properties of the client-side MaskedInput object are maskedInput.masked and maskedInput.unmasked:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;maskedInput.masked refers to the display textbox element that the user sees and edits. It contains the masked text.&lt;br /&gt;Although the masked text is typically not examined on the server, it can be accessed as MaskedInput&amp;#39;s DisplayText property.&lt;/li&gt;&lt;li&gt;maskedInput.unmasked refers to a hidden input that contains the unmasked text.&lt;br /&gt;The unmasked text is often examined or manipulated on the server, where it can be accessed as MaskedInput&amp;#39;s Text property.&lt;/li&gt;&lt;/ul&gt;Hopefully it is now clear how Transforms function. In the next blog post I will explain how you can customize them.&lt;br /&gt;&lt;br /&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.componentart.com/BLOGS/jovan/archive/2008/10/22/maskedinput-transform-functionality.aspx&amp;amp;;subject=MaskedInput+Transform+functionality" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2008/10/22/maskedinput-transform-functionality.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.componentart.com/BLOGS/jovan/archive/2008/10/22/maskedinput-transform-functionality.aspx&amp;amp;;title=MaskedInput+Transform+functionality" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2008/10/22/maskedinput-transform-functionality.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.componentart.com/BLOGS/jovan/archive/2008/10/22/maskedinput-transform-functionality.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2008/10/22/maskedinput-transform-functionality.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.componentart.com/BLOGS/jovan/archive/2008/10/22/maskedinput-transform-functionality.aspx&amp;amp;title=MaskedInput+Transform+functionality" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2008/10/22/maskedinput-transform-functionality.aspx"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.componentart.com/BLOGS/aggbug.aspx?PostID=24615" width="1" height="1"&gt;</content><author><name>Jovan</name><uri>http://www.componentart.com/BLOGS/members/Jovan.aspx</uri></author><category term="JavaScript" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/JavaScript/default.aspx" /><category term="ComponentArt Web.UI" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/ComponentArt+Web.UI/default.aspx" /><category term="Input" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/Input/default.aspx" /><category term="MaskedInput" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/MaskedInput/default.aspx" /></entry><entry><title>Major input control Gotcha</title><link rel="alternate" type="text/html" href="http://www.componentart.com/BLOGS/jovan/archive/2008/10/14/major-input-control-gotcha.aspx" /><id>http://www.componentart.com/BLOGS/jovan/archive/2008/10/14/major-input-control-gotcha.aspx</id><published>2008-10-14T15:17:00Z</published><updated>2008-10-14T15:17:00Z</updated><content type="html">&lt;br /&gt;&lt;strong&gt;Short Story:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This will not work:&lt;br /&gt;&lt;pre style="font-family:courier new;background-color:#e2e2e2;border:#a0a0a0 1px solid;"&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#c71585;"&gt;ComponentArt&lt;/span&gt;:&lt;span style="color:#800000;"&gt;NumberInput&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;runat&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;ID&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;MyNumberInput&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;input&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;type&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;button&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;value&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;+&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;onclick&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;MyNumberInput.increaseValue();&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;input&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;type&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;button&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;value&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;-&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;onclick&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;MyNumberInput.decreaseValue();&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;br /&gt;This is how to correct it:&lt;br /&gt;&lt;pre style="font-family:courier new;background-color:#e2e2e2;border:#a0a0a0 1px solid;"&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#c71585;"&gt;ComponentArt&lt;/span&gt;:&lt;span style="color:#800000;"&gt;NumberInput&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;runat&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;ID&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;MyNumberInput&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;input&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;type&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;button&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;value&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;+&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;onclick&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;&lt;span style="font-weight:bold;background-color:yellow;"&gt;window.&lt;/span&gt;MyNumberInput.increaseValue();&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;input&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;type&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;button&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;value&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;-&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;onclick&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;&lt;span style="font-weight:bold;background-color:yellow;"&gt;window.&lt;/span&gt;MyNumberInput.decreaseValue();&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Long Story:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This will work:&lt;br /&gt;&lt;pre style="font-family:courier new;background-color:#e2e2e2;border:#a0a0a0 1px solid;"&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#c71585;"&gt;ComponentArt&lt;/span&gt;:&lt;span style="color:#800000;"&gt;NumberInput&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;runat&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;ID&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;MyNumberInput&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;input&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;type&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;button&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;value&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;+&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;onclick&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;increase();&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;script&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;type&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;
  function increase()
  {
    MyNumberInput.increaseValue();
  }
&lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;script&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;br /&gt;But, as mentioned before, this:&lt;br /&gt;&lt;pre style="font-family:courier new;background-color:#e2e2e2;border:#a0a0a0 1px solid;"&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#c71585;"&gt;ComponentArt&lt;/span&gt;:&lt;span style="color:#800000;"&gt;NumberInput&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;runat&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;ID&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;MyNumberInput&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;input&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;type&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;button&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;value&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;+&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;onclick&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;&amp;quot;MyNumberInput.increaseValue();&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;will instead produce a JavaScript error: &lt;span style="font-style:italic;font-family:courier new;"&gt;MyNumberInput.increaseValue is not a function&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;But isn&amp;#39;t that the exact same code?? What is going on?&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;It turns out that in the second case &amp;quot;MyNumberInput&amp;quot; is not referring to the client-side NumberInput object. Instead it is referring to a DOM element of the same name.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Like most ComponentArt controls, input controls create a number of client-side DOM elements and JavaScript objects.&lt;br /&gt;In this particular example, with a NumberInput named MyNumberInput:&lt;br /&gt;In JavaScript, the most important object is named &lt;span style="font-family:courier new;"&gt;MyNumberInput&lt;/span&gt;, and is an instance of client-side class &lt;span style="font-family:courier new;"&gt;ComponentArt.Web.UI.NumberInput&lt;/span&gt;.&lt;br /&gt;In the DOM, there are a number of different elements, including a text input with the id &lt;span style="font-family:courier new;"&gt;MyNumberInput&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;This results in a very unusual naming conflict. Normally, when you write &lt;span style="font-family:courier new;"&gt;MyNumberInput&lt;/span&gt; in client-side code, you expect it to refer to the global JavaScript object of that name. And it does. &lt;span style="font-weight:bold;font-style:italic;"&gt;Except&lt;/span&gt; when the code is running in the event handler of an HTML tag. Then &lt;span style="font-family:courier new;"&gt;MyNumberInput&lt;/span&gt; refers to the DOM element with that id. Which is probably not what you want.&lt;br /&gt;&lt;br /&gt;To avoid ambiguity, you can use &lt;span style="font-family:courier new;"&gt;window.MyNumberInput&lt;/span&gt; to refer to the JavaScript object, and &lt;span style="font-family:courier new;"&gt;document.getElementById(&amp;#39;MyNumberInput&amp;#39;)&lt;/span&gt; to refer to the DOM element.&lt;br /&gt;&lt;br /&gt;So why don&amp;rsquo;t we fix this? Well, it turns out that there is no real bug here.&lt;br /&gt;First of all, this is not a design that is unique to ComponentArt input controls. In fact, most ComponentArt controls produce JavaScript objects and DOM elements with matching identifiers, for a number of reasons. What is different with input controls is that the DOM element in question happens to be a form element. This triggers the naming conflict.&lt;br /&gt;However, having these matching identifiers turns out to be needed for the input controls to work smoothly with ASP.NET&amp;rsquo;s client-side validation, which is a very important feature.&lt;br /&gt;So it is unlikely that we will be able to &amp;quot;fix&amp;quot; this. Instead, just please keep this gotcha in mind.&lt;br /&gt;&lt;br /&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.componentart.com/BLOGS/jovan/archive/2008/10/14/major-input-control-gotcha.aspx&amp;amp;;subject=Major+input+control+Gotcha" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2008/10/14/major-input-control-gotcha.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.componentart.com/BLOGS/jovan/archive/2008/10/14/major-input-control-gotcha.aspx&amp;amp;;title=Major+input+control+Gotcha" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2008/10/14/major-input-control-gotcha.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.componentart.com/BLOGS/jovan/archive/2008/10/14/major-input-control-gotcha.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2008/10/14/major-input-control-gotcha.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.componentart.com/BLOGS/jovan/archive/2008/10/14/major-input-control-gotcha.aspx&amp;amp;title=Major+input+control+Gotcha" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2008/10/14/major-input-control-gotcha.aspx"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.componentart.com/BLOGS/aggbug.aspx?PostID=24274" width="1" height="1"&gt;</content><author><name>Jovan</name><uri>http://www.componentart.com/BLOGS/members/Jovan.aspx</uri></author><category term="JavaScript" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/JavaScript/default.aspx" /><category term="ComponentArt Web.UI" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/ComponentArt+Web.UI/default.aspx" /><category term="Input" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/Input/default.aspx" /><category term="NumberInput" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/NumberInput/default.aspx" /><category term="MaskedInput" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/MaskedInput/default.aspx" /></entry><entry><title>Multiline strings in JavaScript</title><link rel="alternate" type="text/html" href="http://www.componentart.com/BLOGS/jovan/archive/2007/10/17/multiline-strings-in-javascript.aspx" /><id>http://www.componentart.com/BLOGS/jovan/archive/2007/10/17/multiline-strings-in-javascript.aspx</id><published>2007-10-17T23:53:00Z</published><updated>2007-10-17T23:53:00Z</updated><content type="html">&lt;br /&gt;Myth: You can&amp;#39;t have a string literal stretch across two lines of text in JavaScript.&lt;br /&gt;&lt;br /&gt;Fact: You can have multiline string literals in JavaScript in all browsers.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Multiline (or is it &amp;quot;multi-line&amp;quot;?) strings are a fringe feature of programming languages. They are very rarely needed, so a lot of languages don&amp;#39;t support them at all (VB.NET). And even when a language does support them (C#), most programmers are not even aware of that. How often have you seen something like this in real code:&lt;br /&gt;&lt;pre style="line-height:120%;font-family:Courier New;"&gt;string myStr = @&amp;quot;This is a C#
multiline string
just because I can!&amp;quot;;&lt;/pre&gt;I think I used that only once. Old &lt;span style="font-family:Courier New;"&gt;&amp;quot;\n&amp;quot;&lt;/span&gt; would have worked alright, but in that case the string was very long. Multiline option was much more readable and also gave me a chance to show off my incredibly amazing super knowledge of this marginal feature. It is this very marginality and near-uselessness that makes multiline strings a topic I want to blog about.&lt;br /&gt;&lt;br /&gt;Actually, JavaScript, being a tricky little scripting language, has an increased need for multiline strings. Use it in depth and you will need statements like eval, which evaluates a string of code, or this textbook example:&lt;br /&gt;&lt;br /&gt;&lt;pre style="line-height:120%;font-family:Courier New;"&gt;var square = new Function(&amp;#39;x&amp;#39;,&amp;#39;return x*x;&amp;#39;);

alert(square(5)); // alerts 25&lt;/pre&gt;&lt;br /&gt;This is actually a very useful feature of the language. Being able to construct code on the fly is certainly not your run-of-the-mill onclick-change-image JavaScript. But if you get deep into the language, the need for it does arise. Problem is, what if the function you want to create is more complex than x*x?&lt;br /&gt;&lt;br /&gt;&lt;pre style="line-height:120%;font-family:Courier New;"&gt;var factorial = new Function(&amp;#39;n&amp;#39;,
  &amp;#39;var result=1; for (var i=1; i&amp;lt;=n; i++) result *= i; return result;&amp;#39;);

alert(5)); // alerts 120&lt;/pre&gt;&lt;br /&gt;That works, but man is it ugly. Too hard to read. Multiline strings to the rescue:&lt;br /&gt;&lt;br /&gt;&lt;pre style="line-height:120%;font-family:Courier New;"&gt;var factorial = new Function(&amp;#39;n&amp;#39;, &amp;#39;\
  var result = 1;            \
  for (var i=1; i&amp;lt;=n; i++)   \
    result *= i;             \
  return result;             \&amp;#39;);

alert(factorial(5)); // alerts 120&lt;/pre&gt;&lt;br /&gt;Yes, that works! And it&amp;#39;s exactly the same as the previous piece of code (aside for extra white space to make it more readable).&lt;br /&gt;&lt;br /&gt;Simply put, you can use backslash character to ignore end of line in JavaScript strings. This directly contradicts my JavaScript books. For example, David Flanagan&amp;#39;s &lt;a href="http://www.amazon.com/JavaScript-Definitive-Guide-David-Flanagan/dp/0596101996/ref=pd_bbs_sr_1/102-3512757-8924107?ie=UTF8&amp;amp;s=books&amp;amp;qid=1190917927&amp;amp;sr=8-1"&gt;[JavaScrip&lt;span&gt;&lt;/span&gt;t: The Definitive Guide]&lt;/a&gt;, my JavaScript bible for almost a decade and counting, specifically says: &lt;span style="font-style:italic;"&gt;backslash escape cannot be used before a line break to continue a string&lt;/span&gt;. This is clearly incorrect. (I am so proud to have found an error in that book, I want to let everyone know.) I tested this technique in all browsers I could think of, and it works in all of them.&lt;br /&gt;&lt;br /&gt;I learned this technique from a Google search that turned up some &lt;a href="http://forums.whirlpool.net.au/forum-replies-archive.cfm/487804.html"&gt;[post on an obscure Australian forum]&lt;/a&gt;. How this one guy was the only enlightened individual is still a mystery.&lt;br /&gt;&lt;br /&gt;Note that the strings will not contain newline characters, unlike the C# multiline example from the beginning of this post. In particular in JavaScrip&lt;span&gt;&lt;/span&gt;t:&lt;br /&gt;&lt;br /&gt;&lt;pre style="line-height:120%;font-family:Courier New;"&gt;alert(&amp;#39;foobar&amp;#39; == &amp;#39;foo bar&amp;#39;); // false
alert(&amp;#39;foobar&amp;#39; == &amp;#39;foobar&amp;#39;);  // true
alert(&amp;#39;foobar&amp;#39; == &amp;#39;foo\
bar&amp;#39;);                        // true!&lt;/pre&gt;&lt;br /&gt;So end of line is simply magically ignored. If you really want to have new line characters, you will have to run something like:&lt;br /&gt;&lt;br /&gt;&lt;pre style="line-height:120%;font-family:Courier New;"&gt;var myStr = &amp;#39;line one\n\
line two&amp;#39;;&lt;/pre&gt;&lt;br /&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.componentart.com/BLOGS/jovan/archive/2007/10/17/multiline-strings-in-javascript.aspx&amp;amp;;subject=Multiline+strings+in+JavaScript" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2007/10/17/multiline-strings-in-javascript.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.componentart.com/BLOGS/jovan/archive/2007/10/17/multiline-strings-in-javascript.aspx&amp;amp;;title=Multiline+strings+in+JavaScript" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2007/10/17/multiline-strings-in-javascript.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.componentart.com/BLOGS/jovan/archive/2007/10/17/multiline-strings-in-javascript.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2007/10/17/multiline-strings-in-javascript.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.componentart.com/BLOGS/jovan/archive/2007/10/17/multiline-strings-in-javascript.aspx&amp;amp;title=Multiline+strings+in+JavaScript" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2007/10/17/multiline-strings-in-javascript.aspx"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.componentart.com/BLOGS/aggbug.aspx?PostID=7716" width="1" height="1"&gt;</content><author><name>Jovan</name><uri>http://www.componentart.com/BLOGS/members/Jovan.aspx</uri></author><category term="JavaScript" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/JavaScript/default.aspx" /><category term="C#" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/C_2300_/default.aspx" /></entry><entry><title>Tackling Stubborn TD Style Definitions</title><link rel="alternate" type="text/html" href="http://www.componentart.com/BLOGS/jovan/archive/2007/06/18/tackling-stubborn-td-style-definitions.aspx" /><id>http://www.componentart.com/BLOGS/jovan/archive/2007/06/18/tackling-stubborn-td-style-definitions.aspx</id><published>2007-06-18T21:05:00Z</published><updated>2007-06-18T21:05:00Z</updated><content type="html">&lt;p&gt;&lt;strong&gt;&lt;br /&gt;&amp;quot;&lt;/strong&gt;&lt;em&gt;If you set a default style for the td tag in your stylesheet, like this,&lt;br /&gt;td {font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #333333;}&lt;br /&gt;then this will be used in your tab strip, no matter what style you create for the tab items&lt;/em&gt;&lt;strong&gt;&amp;quot;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Questions like this are quite common in forums and support calls.&amp;nbsp; An obvious way to avoid this conflict is to not have a default style for TD tags. However, this is not always practical - default TD style definitions are quite common, sometimes even mandated by corporate policy.&amp;nbsp; Instead, there is a lot less intrusive way to get this to work.&amp;nbsp; First let&amp;#39;s take a look at an example of how this happens.&lt;/p&gt;&lt;p&gt;Suppose we have a page which contains a CSS definition like this, instructing table cells to use Comic font:&lt;/p&gt;&lt;pre style="line-height:100%;font-family:Courier New;"&gt;TD
{
  font-family:&amp;quot;Comic Sans MS&amp;quot;;
}&lt;/pre&gt;&lt;p&gt;However we want to show menu items in Courier font:&lt;/p&gt;&lt;pre style="line-height:100%;font-family:Courier New;"&gt;.myMenuItem
{
  font-family:&amp;quot;Courier New&amp;quot;;
}&lt;/pre&gt;&lt;p&gt;This looks like it should work, and it sometimes does. But more often it doesn&amp;#39;t: Menu items (or TabStrip tabs, or NavBar items...) use Comic Sans font from the default TD style, instead of Courier New from myMenuItem CSS class.&amp;nbsp; To understand why, let&amp;#39;s take a look at a (simplified) sample of HTML that is rendered by the menu for its item:&lt;/p&gt;&lt;pre style="line-height:100%;font-family:Courier New;"&gt;&amp;lt;td class=&amp;quot;myMenuItem&amp;quot;&amp;gt;
 ITEM TEXT
&amp;lt;/td&amp;gt;&lt;/pre&gt;&lt;p&gt;In this first case definitions applied in myMenuItem CSS class will correctly take effect.&amp;nbsp; However, in many cases - for example, when the item has an icon -&amp;nbsp;the rendered HTML is more complex:&lt;/p&gt;&lt;pre style="line-height:100%;font-family:Courier New;"&gt;&amp;lt;td&amp;gt;
 &amp;lt;table class=&amp;quot;myMenuItem&amp;quot;&amp;gt;
  &amp;lt;tr&amp;gt;
   &amp;lt;td&amp;gt;
    &amp;lt;img src=&amp;quot;icon.gif&amp;quot; mce_src=&amp;quot;icon.gif&amp;quot;&amp;gt;
   &amp;lt;/td&amp;gt;
   &amp;lt;td&amp;gt;
    ITEM TEXT
   &amp;lt;/td&amp;gt;
  &amp;lt;/tr&amp;gt;
 &amp;lt;/table&amp;gt;
&amp;lt;/td&amp;gt;&lt;/pre&gt;&lt;p&gt;In this case, style definitons for default TD element will take precedence over definitions for myMenuItem CSS class. The item will show in Comic font instead of the desired Courier.&lt;/p&gt;&lt;p&gt;There is a very simple CSS workaround for this situation. Just slightly modify the original definition to get:&lt;/p&gt;&lt;pre style="line-height:100%;font-family:Courier New;"&gt;.myMenuItem &lt;strong&gt;TD&lt;/strong&gt;
{
  font-family:&amp;quot;Courier New&amp;quot;;
}&lt;/pre&gt;&lt;p&gt;The meaning of this defintion is: &lt;strong&gt;if a TD tag is within a tag of class myMenuItem&lt;/strong&gt;, show it in Courier New font. &amp;nbsp;This is more specific than the default TD style we&amp;#39;re trying to overrule, so it will win out.&amp;nbsp; Note however, that while this definition will work in the second case (the more complex item), it will not work in the first (the simple item).&amp;nbsp; So finally the solution that works for all cases is a combination of the two:&lt;/p&gt;&lt;pre style="line-height:100%;font-family:Courier New;"&gt;&lt;strong&gt;.myMenuItem, .myMenuItem TD
{
  font-family:&amp;quot;Courier New&amp;quot;;
}&lt;/strong&gt;&lt;/pre&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.componentart.com/BLOGS/jovan/archive/2007/06/18/tackling-stubborn-td-style-definitions.aspx&amp;amp;;subject=Tackling+Stubborn+TD+Style+Definitions" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2007/06/18/tackling-stubborn-td-style-definitions.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.componentart.com/BLOGS/jovan/archive/2007/06/18/tackling-stubborn-td-style-definitions.aspx&amp;amp;;title=Tackling+Stubborn+TD+Style+Definitions" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2007/06/18/tackling-stubborn-td-style-definitions.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.componentart.com/BLOGS/jovan/archive/2007/06/18/tackling-stubborn-td-style-definitions.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2007/06/18/tackling-stubborn-td-style-definitions.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.componentart.com/BLOGS/jovan/archive/2007/06/18/tackling-stubborn-td-style-definitions.aspx&amp;amp;title=Tackling+Stubborn+TD+Style+Definitions" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2007/06/18/tackling-stubborn-td-style-definitions.aspx"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.componentart.com/BLOGS/aggbug.aspx?PostID=4606" width="1" height="1"&gt;</content><author><name>Jovan</name><uri>http://www.componentart.com/BLOGS/members/Jovan.aspx</uri></author><category term="ComponentArt Web.UI" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/ComponentArt+Web.UI/default.aspx" /><category term="CSS" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/CSS/default.aspx" /></entry><entry><title>Client-side Date Format Localization in ASP.NET AJAX</title><link rel="alternate" type="text/html" href="http://www.componentart.com/BLOGS/jovan/archive/2006/12/01/client-side-date-format-localization-in-asp-net-ajax.aspx" /><id>http://www.componentart.com/BLOGS/jovan/archive/2006/12/01/client-side-date-format-localization-in-asp-net-ajax.aspx</id><published>2006-12-02T06:03:00Z</published><updated>2006-12-02T06:03:00Z</updated><content type="html">&lt;p&gt;Much buzz has already been created around new client-side localization features introduced with ASP.NET AJAX Beta 2. Most of it has focused on localized resources, which can now easily be retrieved from the server by client scripts. This makes sense - resources are arguably the most important aspect of localization. But not from a web control developer&amp;#39;s point of view. When developing web controls, we deal with little actual content - for the most part, we are providing form for our customers&amp;#39; content. Having worked on ComponentArt.Web.UI Calendar control in particular, I was especially interested in localization features that deal with date and time formats. &lt;/p&gt;&lt;p&gt;&lt;strong&gt;How Calendar Works Today&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;In order for Calendar control to be customizable and culture-independent, we send information about date settings to the client, where the rendering is to take place. Examine the HTML source of a page that contains a Calendar control and you will see excerpts like these: &lt;/p&gt;&lt;pre style="padding-right:5px;padding-left:15px;font-size:8pt;padding-bottom:5px;margin:5px;padding-top:5px;font-family:Courier New;"&gt;[&amp;#39;AbbreviatedDayNames&amp;#39;,[&amp;#39;Sun&amp;#39;,&amp;#39;Mon&amp;#39;,&amp;#39;Tue&amp;#39;,&amp;#39;Wed&amp;#39;,&amp;#39;Thu&amp;#39;,&amp;#39;Fri&amp;#39;,&amp;#39;Sat&amp;#39;]]
[&amp;#39;AbbreviatedMonthNames&amp;#39;,[&amp;#39;Jan&amp;#39;,&amp;#39;Feb&amp;#39;,&amp;#39;Mar&amp;#39;,&amp;#39;Apr&amp;#39;,&amp;#39;May&amp;#39;,&amp;#39;Jun&amp;#39;,&amp;#39;Jul&amp;#39;,
  &amp;#39;Aug&amp;#39;,&amp;#39;Sep&amp;#39;,&amp;#39;Oct&amp;#39;,&amp;#39;Nov&amp;#39;,&amp;#39;Dec&amp;#39;]]
[&amp;#39;DayNames&amp;#39;,[&amp;#39;Sunday&amp;#39;,&amp;#39;Monday&amp;#39;,&amp;#39;Tuesday&amp;#39;,&amp;#39;Wednesday&amp;#39;,&amp;#39;Thursday&amp;#39;,
  &amp;#39;Friday&amp;#39;,&amp;#39;Saturday&amp;#39;]]
[&amp;#39;MonthNames&amp;#39;,[&amp;#39;January&amp;#39;,&amp;#39;February&amp;#39;,&amp;#39;March&amp;#39;,&amp;#39;April&amp;#39;,&amp;#39;May&amp;#39;,&amp;#39;June&amp;#39;,
  &amp;#39;July&amp;#39;,&amp;#39;August&amp;#39;,&amp;#39;September&amp;#39;,&amp;#39;October&amp;#39;,&amp;#39;November&amp;#39;,&amp;#39;December&amp;#39;]]&lt;/pre&gt;&lt;p&gt;These are portions of JavaScript arrays with relevant date format information. They are put together by the Calendar control on the server, to be used by the control&amp;#39;s rendering engine on the client. The original source of information is ASP.NET&amp;#39;s System.Globalization namespace (unless, of course, the developer specifically instructs the Calendar control instance to use some custom date formats). It is the wealth of information in the framework that enables the Calendar to seamlessly switch between various cultures as seen in the &lt;a href="http://www.componentart.com/entry.aspx?id=71&amp;amp;page=http://webui.componentart.com/calendar/features/globalization/WebForm1.aspx"&gt;[Globalization demo]&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;strong&gt;What ASP.NET AJAX Brings&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;So I was really delighted to hear that as of ASP.NET AJAX Beta 2, this information is also available on the client. Only information for current culture (on the server: &lt;span style="font-family:courier new;"&gt;System.Globalization.CultureInfo.CurrentCulture&lt;/span&gt;) is being propagated to the client, which makes perfect sense with - count them - 134 cultures and growing. Full documentation on this feature is not yet available, but I did a little snooping around - using the good old for/in loop mentioned in &lt;a href="http://www.componentart.com/entry.aspx?id=71&amp;amp;page=http://blogs.componentart.com/jovan/archive/2006/11/28/quick-conversions-to-simple-types-in-javascript.aspx"&gt;[my previous blog post]&lt;/a&gt;, and here&amp;#39;s what I found out. The relevant client-side object is called &lt;span style="font-family:courier new;"&gt;Sys.CultureInfo.CurrentCulture.dateTimeFormat&lt;/span&gt;, and its contents for my English (Canada) culture are: &lt;/p&gt;&lt;pre style="padding-right:5px;padding-left:15px;font-size:8pt;padding-bottom:5px;margin:5px;padding-top:5px;font-family:Courier New;"&gt;AMDesignator: AM
Calendar: [object Object]
DateSeparator: /
FirstDayOfWeek: 0
CalendarWeekRule: 0
FullDateTimePattern: dddd, MMMM dd, yyyy h:mm:ss tt
LongDatePattern: dddd, MMMM dd, yyyy
LongTimePattern: h:mm:ss tt
MonthDayPattern: MMMM dd
PMDesignator: PM
RFC1123Pattern: ddd, dd MMM yyyy HH&amp;#39;:&amp;#39;mm&amp;#39;:&amp;#39;ss &amp;#39;GMT&amp;#39;
ShortDatePattern: M/d/yyyy
ShortTimePattern: h:mm tt
SortableDateTimePattern: yyyy&amp;#39;-&amp;#39;MM&amp;#39;-&amp;#39;dd&amp;#39;T&amp;#39;HH&amp;#39;:&amp;#39;mm&amp;#39;:&amp;#39;ss
TimeSeparator: :
UniversalSortableDateTimePattern: yyyy&amp;#39;-&amp;#39;MM&amp;#39;-&amp;#39;dd HH&amp;#39;:&amp;#39;mm&amp;#39;:&amp;#39;ss&amp;#39;Z&amp;#39;
YearMonthPattern: MMMM, yyyy
AbbreviatedDayNames: Sun,Mon,Tue,Wed,Thu,Fri,Sat
ShortestDayNames: Su,Mo,Tu,We,Th,Fr,Sa
DayNames: Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday
AbbreviatedMonthNames: Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,
  Dec,
MonthNames: January,February,March,April,May,June,July,August,
  September,October,November,December,
IsReadOnly: false
NativeCalendarName: Gregorian Calendar
AbbreviatedMonthGenitiveNames: Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,
  Oct,Nov,Dec,
MonthGenitiveNames: January,February,March,April,May,June,July,
  August,September,October,November,December,&lt;/pre&gt;&lt;p&gt;Further drilling into &lt;span style="font-family:courier new;"&gt;Sys.CultureInfo.CurrentCulture.dateTimeFormat.Calendar&lt;/span&gt;, we find:&lt;/p&gt;&lt;pre style="padding-right:5px;padding-left:15px;font-size:8pt;padding-bottom:5px;margin:5px;padding-top:5px;font-family:Courier New;"&gt;MinSupportedDateTime: Thu Dec 31 19:00:00 EST 99
MaxSupportedDateTime: Fri Dec 31 18:59:59 EST 9999
AlgorithmType: 1
CalendarType: 1
Eras: 1
TwoDigitYearMax: 2029
IsReadOnly: false&lt;/pre&gt;&lt;p&gt;As you can see, a lot of this information duplicates the settings propagated by the Calendar control. This is great, because I love to throw code away. In the near future, we will hopefully be able to rely on the client-side framework to provide date and time format information, and only propagate it ourselves when necessary. &lt;/p&gt;&lt;p&gt;You can use this data for your own needs with confidence. While it is not yet documented, and has the appearance of some internal code, good folks of the ASP.NET AJAX team confirm that it will be in this same form and public, supported, and documented when ASP.NET AJAX is released. Until client-side docs are available, you can rely on the server-side documentation for DateTimeFormatInfo. Client-side object is designed to duplicate it. &lt;/p&gt;&lt;p&gt;It feels great to see more and more of the ASP.NET framework migrate (or rather replicate itself) to the client. Soon we will all benefit from building and using a much better interweb. &lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.componentart.com/BLOGS/jovan/archive/2006/12/01/client-side-date-format-localization-in-asp-net-ajax.aspx&amp;amp;;subject=Client-side+Date+Format+Localization+in+ASP.NET+AJAX" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2006/12/01/client-side-date-format-localization-in-asp-net-ajax.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.componentart.com/BLOGS/jovan/archive/2006/12/01/client-side-date-format-localization-in-asp-net-ajax.aspx&amp;amp;;title=Client-side+Date+Format+Localization+in+ASP.NET+AJAX" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2006/12/01/client-side-date-format-localization-in-asp-net-ajax.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.componentart.com/BLOGS/jovan/archive/2006/12/01/client-side-date-format-localization-in-asp-net-ajax.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2006/12/01/client-side-date-format-localization-in-asp-net-ajax.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.componentart.com/BLOGS/jovan/archive/2006/12/01/client-side-date-format-localization-in-asp-net-ajax.aspx&amp;amp;title=Client-side+Date+Format+Localization+in+ASP.NET+AJAX" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2006/12/01/client-side-date-format-localization-in-asp-net-ajax.aspx"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.componentart.com/BLOGS/aggbug.aspx?PostID=58" width="1" height="1"&gt;</content><author><name>Jovan</name><uri>http://www.componentart.com/BLOGS/members/Jovan.aspx</uri></author><category term="ASP.NET AJAX" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/ASP.NET+AJAX/default.aspx" /><category term="Calendar" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/Calendar/default.aspx" /></entry><entry><title>Quick Type Conversions and Other JavaScript Tricks</title><link rel="alternate" type="text/html" href="http://www.componentart.com/BLOGS/jovan/archive/2006/11/28/quick-conversions-to-simple-types-in-javascript.aspx" /><id>http://www.componentart.com/BLOGS/jovan/archive/2006/11/28/quick-conversions-to-simple-types-in-javascript.aspx</id><published>2006-11-29T07:28:00Z</published><updated>2006-11-29T07:28:00Z</updated><content type="html">&lt;p&gt;I recently read a post in &lt;a href="http://weblogs.asp.net/bleroy/"&gt;[Bertrand Le Roy&amp;#39;s blog]&lt;/a&gt; titled &lt;a href="http://weblogs.asp.net/bleroy/archive/2006/09/29/A-nice-and-compact-way-to-coerce-to-Boolean-in-JavaScript.aspx"&gt;[A nice and compact way to coerce to Boolean in JavaScript]&lt;/a&gt;. Having used JavaScript extensively for the past few years, I knew from the title what the post would be about - the lovely double negation: &lt;span class="SourceCode"&gt;!!somevariable&lt;/span&gt; - the shortest way to say &amp;quot;parse boolean&amp;quot; in JavaScript. While the trick was not new to me, the blog post did give me the idea to share a couple of similar tips:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Type Conversions&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;A compact way to convert to integer: &lt;span class="SourceCode"&gt;somevariable - 0&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A compact way to convert to string: &lt;span class="SourceCode"&gt;somevariable + &amp;#39;&amp;#39;&lt;/span&gt; &lt;/p&gt;None of these may be very readable at first, but I found them very easy to get used to. They certainly are short to write, which counts when writing web controls. And frankly, I never was a big fan of &amp;quot;parseInt&amp;quot;.&lt;br /&gt;&lt;br /&gt;Note also that &lt;span style="font-family:courier new;"&gt;parseInt(somevariable)&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;somevariable-0&lt;/span&gt; are not equivalent. For example, &lt;span style="font-family:courier new;"&gt;parseInt(true)&lt;/span&gt; evaluates to &lt;span style="font-family:courier new;"&gt;NaN&lt;/span&gt;, while &lt;span style="font-family:courier new;"&gt;true-0&lt;/span&gt; evaluates to &lt;span style="font-family:courier new;"&gt;1&lt;/span&gt;. I prefer the latter.&lt;br /&gt;&lt;p&gt;I first learned these three tricks from David Flanagan&amp;#39;s &lt;a href="http://www.amazon.com/JavaScript-Definitive-Guide-David-Flanagan/dp/0596101996/sr=8-1/qid=1164781291/ref=pd_bbs_sr_1/102-3512757-8924107?ie=UTF8&amp;amp;s=books"&gt;[JavaScr&lt;span&gt;&lt;/span&gt;ipt: The Definitive Guide]&lt;/a&gt;, a terrific book.&lt;/p&gt;&lt;p&gt;Here are a couple more tricks I learned from that book (or was it somewhere else?):&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Undefined vs &lt;span style="font-family:courier new;"&gt;null&lt;/span&gt; and &lt;/strong&gt;&lt;span style="font-family:courier new;"&gt;===&lt;/span&gt;&lt;strong&gt; vs &lt;/strong&gt;&lt;span style="font-family:courier new;"&gt;==&lt;/span&gt;&lt;/p&gt;When you just a declare a variable &lt;span style="font-family:courier new;"&gt;foo&lt;/span&gt;, but you do not assign a value to it, what is its value? You may think it is &lt;span style="font-family:courier new;"&gt;null&lt;/span&gt;, because &lt;span style="font-family:courier new;"&gt;foo==null&lt;/span&gt; evaluates to &lt;span style="font-family:courier new;"&gt;true&lt;/span&gt;, but this is not exactly correct. The value is actually undefined - or unassigned, if you prefer. You can prove this by using the identity operator, &lt;span style="font-family:courier new;"&gt;===&lt;/span&gt;:&lt;br /&gt;&lt;pre style="margin-top:5px;margin-left:5px;margin-right:5px;font-family:courier new;background-color:#e2e2e2;border:#a0a0a0 1px solid;padding:5px;"&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; foo;
&lt;span style="color:#0000ff;"&gt;alert&lt;/span&gt;(foo == &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;); &lt;span style="color:#008000;"&gt;// true&lt;/span&gt;
&lt;span style="color:#0000ff;"&gt;alert&lt;/span&gt;(foo === &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;); &lt;span style="color:#008000;"&gt;// false&lt;/span&gt;
&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; o = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; Object();
&lt;span style="color:#0000ff;"&gt;alert&lt;/span&gt;(o.bar == &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;); &lt;span style="color:#008000;"&gt;// true&lt;/span&gt;
&lt;span style="color:#0000ff;"&gt;alert&lt;/span&gt;(o.bar === &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;); &lt;span style="color:#008000;"&gt;// false&lt;/span&gt;
&lt;span style="color:#0000ff;"&gt;alert&lt;/span&gt;(o.bar == foo); &lt;span style="color:#008000;"&gt;// true&lt;/span&gt;
&lt;span style="color:#0000ff;"&gt;alert&lt;/span&gt;(o.bar === foo); &lt;span style="color:#008000;"&gt;// true&lt;/span&gt;
&lt;span style="color:#0000ff;"&gt;alert&lt;/span&gt;(foo === &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; 0); &lt;span style="color:#008000;"&gt;// true&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;The last line uses the operator &lt;span style="font-family:courier new;"&gt;void&lt;/span&gt;, another recluse. Its purpose is to discard the value of its operand and return an undefined value instead. If you are writing code and need an undefined value, you should do what cool kids do and use &lt;span style="font-family:courier new;"&gt;void 0&lt;/span&gt;, instead of an unassigned dummy variable or something else lame.&lt;/p&gt;&lt;p&gt;So: undefined value is not null value, which can be proven using the identity operator, which is not the equality operator. But will you actually need this any time soon? Probably not. Identity operator, undefined value, and &lt;span style="font-family:courier new;"&gt;void&lt;/span&gt; operator are used more often in examples like this one than in actual code. But I did occasionally have a need for them, so it pays to keep them in mind. Also they&amp;#39;re fun to blog about.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="font-family:courier new;"&gt;for/in&lt;/span&gt; Loop&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;In contrast, &lt;span style="font-family:courier new;"&gt;for/in&lt;/span&gt; loop is very important in JavaScript. It enables looping through the properties of an object. This is indispensable in some cases - for example when you need to examine an unknown object: &lt;/p&gt;&lt;pre style="margin-top:5px;margin-left:5px;margin-right:5px;font-family:courier new;background-color:#e2e2e2;border:#a0a0a0 1px solid;padding:5px;"&gt;&lt;span style="color:#0000ff;"&gt;for&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; propertyName &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; myObject)
{
  &lt;span style="color:#0000ff;"&gt;alert&lt;/span&gt;(&amp;#39;Property &amp;#39; + propertyName + &amp;#39; has value: &amp;#39; + myObject[propertyName]);
}&lt;/pre&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.componentart.com/BLOGS/jovan/archive/2006/11/28/quick-conversions-to-simple-types-in-javascript.aspx&amp;amp;;subject=Quick+Type+Conversions+and+Other+JavaScript+Tricks" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2006/11/28/quick-conversions-to-simple-types-in-javascript.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.componentart.com/BLOGS/jovan/archive/2006/11/28/quick-conversions-to-simple-types-in-javascript.aspx&amp;amp;;title=Quick+Type+Conversions+and+Other+JavaScript+Tricks" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2006/11/28/quick-conversions-to-simple-types-in-javascript.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.componentart.com/BLOGS/jovan/archive/2006/11/28/quick-conversions-to-simple-types-in-javascript.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2006/11/28/quick-conversions-to-simple-types-in-javascript.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.componentart.com/BLOGS/jovan/archive/2006/11/28/quick-conversions-to-simple-types-in-javascript.aspx&amp;amp;title=Quick+Type+Conversions+and+Other+JavaScript+Tricks" target="_blank" title = "Post http://www.componentart.com/BLOGS/jovan/archive/2006/11/28/quick-conversions-to-simple-types-in-javascript.aspx"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.componentart.com/BLOGS/aggbug.aspx?PostID=56" width="1" height="1"&gt;</content><author><name>Jovan</name><uri>http://www.componentart.com/BLOGS/members/Jovan.aspx</uri></author><category term="JavaScript" scheme="http://www.componentart.com/BLOGS/jovan/archive/tags/JavaScript/default.aspx" /></entry></feed>