Response.WriteLine()

Even today, many developers use the classic debugging ‘tool’,

Response.Write()

, when developing ASP/ASP.NET applications. Typically, this is the choice when someone wants to do quick debugging in a page – check variable values at runtime, write trace messages, path coverage, etc without resorting to any IDE or other full-fledged debugging tools. However, the problem with

Response.Write()

(in the context of debugging) is that it writes data without any line breaks, which doesn’t help many times. So, given the new set of capabilities in the .NET framework, why not have the

Console.WriteLine()

counterpart for

Response.Write()

too? Here is what I came up with – an extension method for

System.Web.HttpResponse

class that gives line break!

public
static
class
HttpResponseExtensions

{

    public
static
void WriteLine (this
HttpResponse resp, object o)

    {

        resp.Write (o + “<br/>”);

    }

}

As you can see, this extension method simply does the trick of appending a <br /> with the argument passed in. Way by which this method can be utilized include having it in a base page class from which your other pages derive from, have it in a utility class, etc, etc. Choice is yours! J