The Page exposes a <b>Trace</b> property (of type "TraceContext") which can be used to output debugging statements to the page output, provided tracing is enabled.
Using the TraceContext, you can write debugging statements using the <b>Trace.Write</b> and <b>Trace.Warn</b> methods, which each take category
and message strings as arguments. Trace.Warn statements are identical to Trace.Write statements, except they are output in <span style="color:red">red</span>.
<div class="code"><pre>
Trace.Write("Custom Trace","Beginning User Code...");
...
Trace.Warn("Custom Trace","Array count is null!");
</pre></div>
<p>
When Tracing is disabled (i.e. Trace="false" on the page directive, or not present), these statements will not execute and no trace output
will appear in the client browser. This makes it possible to keep debugging statements in production code and enable them conditionally
at a later time.
<p>
Often you will need to execute additional code to construct the statements to pass to the Trace.Write or Trace.Warn methods, where this
code should only execute if tracing is enabled for the page. To support this, the Page exposes a boolean property,
<b>Trace.IsEnabled</b>, which returns true only if tracing is enabled for the page. You should check this property first to guarantee your
debugging code will only execute when tracing is on.
<div class="code"><pre>
if (Trace.IsEnabled)
{
for (int i=0; i<ds.Tables["Categories"].Rows.Count; i++)
<li>Page-level tracing is enabled using a Trace="true" attribute on the top-level Page directive.
<li>Page-level tracing allows developers to write debugging statements as part of a page's client output. Trace statements are output using the Trace.Write and Trace.Warn methods, passing a category and message for each statement.
<li>Debugging code may be conditionally executed depending on whether Trace is enabled for the page. Use the Trace.IsEnabled property of the Page to determine whether tracing is enabled.