O'Reilly logo

Professional ASP.NET 3.5 AJAX by Matt Gibbs, Dan Wahlin, Bill Evjen, Dave Reed

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4.3. Base Class Library

The AJAX Library takes a familiar set of features from the base class library of the .NET Framework and brings it to JavaScript in the browser for you to use in building your applications. It is by no means an equivalent set of functionality as what the base class library offers, but it does go a long way toward simplifying your JavaScript coding tasks.

4.3.1. The String Class

Basic support for removing whitespace is added to JavaScript strings with new methods. The trim() method performs the equivalent of trimStart() and trimEnd(). The instance of the string is not modified by the trim calls. Instead, a copy of the string is returned with the requested change. Listing 4-14 demonstrates using the trim(), trimStart(), and trimEnd() functions.

Example 4-14. Working with the String class
<%@ Page Language="C#" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Using Trim Functions</title>

    <script type="text/javascript">

        function pageLoad(sender, args) {

            var one = ' leading whitespace';
            var two = 'trailing whitespace ';
            var three = ' leading and trailing whitespace ';

            alert('.' + one.trimStart() + '.');
            alert(one);  //the original string is not modified
            alert('.' + two.trimEnd() + '.');
            alert('.' + three.trim() + '.');

        }

    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
    </div>
    </form>
</body>
</html>

The trim methods are just shortcuts to what ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required