ASP.NET AJAX and Sys.Debug

ASP.NET includes tracing functionality that can be used to track different issues in an application.  It can be used to easily inspect errors that have occurred, check sessions IDs, cookie values, ViewState size, server variables plus a lot more. 

The ASP.NET AJAX client script library also includes basic tracing functionality that can be used to write trace messages to a console window (that show up while debugging) or to the actual page.  The client-side tracing functionality can also be used to dump values contained within a JSON object so that they are easily viewed.  All of this client-side tracing functionality is exposed by the Sys.Debug class.  An example of using it to write a trace message to the console and dump the contents of an Album object is shown next:

<script type="text/javascript">
    
function DisplayAlbum()
    {
        
var album = new ASPAJAX.Samples.Album();
        
album.set_title("Sam's Town");
        
album.set_artist("The Killers");
        
Sys.Debug.trace("Set album title and artist properties");

        
$get("lblTitle").innerHTML album.get_title();
        
$get("lblArtist").innerHTML album.get_artist();

        
Sys.Debug.trace("Album properties written out to page");
        
Sys.Debug.traceDump(album,"Album Details:");
    
}
</script>

Adding calls to Sys.Debug.trace() will cause the trace information to be shown in the Visual Studio .NET 2005 console window while debugging, but the trace information won't be shown in the page.  In cases where you'd like to see the output of different trace statements directly in the page you can add a textArea tag and give it an id of TraceConsole as shown next:

<textarea id="TraceConsole" rows="25" cols="60"></textarea>

comments powered by Disqus

2 Comments

Comments have been disabled for this content.