Sys.Debug in Asp.Net Ajax Framework

Every developer needs to debug his applications. There are two ways:

  • Debugging - step-by-step tracking of an application process.
  • Tracing - monitoring of application processes without breaking and writing useful information in a special console.

Asp.Net developers wrote the great Ajax Framework. There is so much stuff for professionals and beginner developers.
Also they didn't forget about debugging tools. (may be was done firstOpen-mouthed)

class Sys.Debug contains 5 methods:

   1:  // output the text message into Debug Console
   2:  Sys.Debug.trace(text);
   3:  // output the information about specified object into Debug Console.
   4:  // second parameter (object name) - is optional
   5:  Sys.Debug.traceDump(object, name);
   6:  // clear Debug Console*
   7:  Sys.Debug.clearTrace();
* - it doesn't clear Debug Console of your default Debugger(more information below the post).
   1:  // output the message only if(condition == true)
   2:  // if the third parameter is specified and set to true then name of the caller function will be shown
   3:  Sys.Debug.assert(condition, message, displayCaller);
   4:  // output the message into Debug Console and break program into default debugger in the invocation point
   5:  Sys.Debug.fail(message);
 
So, what does "Debug Console" mean?
Let`s see the core of Asp.Net Ajax Framework (MicrosoftAjax.js).
There are 2 interesting methods:
 
   1:  // output the text message into Debug Console window of your current debugger.
   2:  this._appendConsole(text);
   3:  // output the text message into textarea in the webform (more information below the text)
   4:  this._appendTrace(text);
Debugger Console may looks like that (Output window in your favorite Visual Studio):

 

VS_debug_console 

Or like that (Console tab in Firebug plugin for Mozilla Firefox):

firebug_output

Or something else.

 

So, what does second method do?

   1:  this._appendTrace(text);
Follow it source:
   1:  var traceElement = document.getElementById('TraceConsole');
   2:  if (traceElement && (traceElement.tagName.toUpperCase() === 'TEXTAREA'))
   3:  {
   4:       traceElement.value += text + '\n';
   5:  }

It looks up an element with ID="TraceConsole" in a webform and verify for the "textarea" type. If well done, message will be written into this element.

Exactly  that Console will be cleaned by the method

   1:  Sys.Debug.clearTrace();

Sys.Debug works only if:

  1. debug="true" in Web.config
   1:  <compilation debug="true">

      2.    ScriptMode="Debug" or ScriptMode="Inherit" (it will be inherited from web.config ) in ScriptManager in the page.

   1:  <asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Debug">

In conclusion I want to say, that Sys.Debug saves my time and nerves. What about you?

Published Thursday, November 22, 2007 2:27 AM by Neu Romantic

Comments

# re: Sys.Debug in Asp.Net Ajax Framework

Monday, November 26, 2007 8:16 AM by Alexey Kucherenko

Hello Roman, nice article.

# re: Sys.Debug in Asp.Net Ajax Framework

Monday, November 26, 2007 8:24 AM by John Davis

the article is really awesome.

You use firebug for FireFox, could you tell me what should I use for IE7?

# Links del 8 de Diciembre: ASP.NET, ASP.NET AJAX, ASP.NET MVC, .NET, VS 2008 &laquo; Thinking in .NET

Pingback from  Links del 8 de Diciembre: ASP.NET, ASP.NET AJAX, ASP.NET MVC, .NET, VS 2008 &laquo; Thinking in .NET

# re: Sys.Debug in Asp.Net Ajax Framework

Monday, December 10, 2007 3:40 AM by Neu Romantic

> You use firebug for FireFox, could you tell me what should I use for IE7?

As i wrote, you can use Visual Studio Debug Output window or you can install firebug lite.

Thanks, Roman.

# Pawel Klimczyk WebLog &raquo; Blog Archive &raquo; Visual Studio 2008 developers links !

Pingback from  Pawel Klimczyk WebLog  &raquo; Blog Archive   &raquo; Visual Studio 2008 developers links !

# Debugging auf die Console in Web Anwendungen

Sunday, January 20, 2008 8:23 AM by Weltretter.com blog

Debugging auf die Console in Web Anwendungen

# re: Sys.Debug in Asp.Net Ajax Framework

Tuesday, January 29, 2008 10:43 AM by Art Long

The Trace helps, but I need to step through the .Net generated code to find an exception error. How do I do that?

# re: Sys.Debug in Asp.Net Ajax Framework

Thursday, January 31, 2008 7:35 PM by Neu Romantic

[quote] 

Art Long

The Trace helps, but I need to step through the .Net generated code to find an exception error. How do I do that?

[/quote]

Try to use Firefox with firebug enabled.

Do you have access to .Net library which generate code ?

Leave a Comment

(required) 
(required) 
(optional)
(required)