08.01.2015 Views

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

348<br />

CHAPTER 14 ■ JAVASCRIPT PROGRAMMING WITH <strong>ASP</strong>.<strong>NET</strong> <strong>AJAX</strong><br />

Boolean Type Extensions<br />

The Boolean language extensions provide for Booleans in JavaScript in a manner that<br />

may be more familiar to .<strong>NET</strong> programmers. In addition to the traditional Boolean enumerations<br />

of true <strong>and</strong> false, it provides a shortcut to instantiating a Boolean value<br />

through the parse function.<br />

So, in JavaScript, you can now create Boolean objects in the following manner:<br />

Var a = new Boolean(true);<br />

Var b = new Boolean(false);<br />

If (a==true)<br />

// Do Something<br />

Var c = Boolean.parse("true");<br />

If (c == true)<br />

// Do Something else<br />

Date Type Extensions<br />

<strong>ASP</strong>.<strong>NET</strong> <strong>AJAX</strong> provides a number of extensions to the Date object in JavaScript through<br />

its Date class. This gives extensions around locale specifics <strong>and</strong> easier instantiation of<br />

dates from strings.<br />

Formatting a Date<br />

The format function on the Date class provides a way to format a Date value into a set output<br />

format. It uses the st<strong>and</strong>ard DateTime format strings. For example, if you have a Date<br />

function <strong>and</strong> you want to render it using the default shortDatePattern type, you would<br />

simply say<br />

var a = myDate.format("d");<br />

where d is the st<strong>and</strong>ard format specified for shortDatePattern.<br />

Formatting a Date Using Locale<br />

If you want to format a date according to the current locale on the machine, you must<br />

first set the EnableScriptGlobalization property on the ScriptManager control to true. You<br />

will also need to ensure that the culture attribute of the web site is set to auto using<br />

<strong>Web</strong>.config.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!