Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What's the difference between Response.Write() and Response.Output.Write()?

user-image
Question added by Muhammad Kamran Khatri , Project Manager , Etisalat
Date Posted: 2014/02/17
Fahad Sattar Mughal
by Fahad Sattar Mughal , Project Manager ERP and MIS/IT , Intercoil Group of Companies

Response.Output.Write() gives you String.Format-style formatted output and the Response.Write() doesn't. FOR ExampleResponse.Write("Current Date Time is "+DateTime.Now.ToString()); Response.Output.Write("{0} is {1:d}", "Current Date Time is: ",DateTime.Now);

Tanweer Ahmed
by Tanweer Ahmed , Application Developer , Department of Revenue,Registration and Land Reforms,Government of Jharkhand

Response.Write and Response.Output.Write are both used to write messages on the screen

 

the only diffrence is Response.Output.Write allows us to write a more formatted output

Arun Raj Alampatta
by Arun Raj Alampatta , Senior Software Engg. , Orion India Systems

In ASP.NET the Response object is of type HttpResponse and when you say Response.Write you're really saying (basically) HttpContext.Current.Response.Write and calling one of the many overloaded Write methods of HttpResponse. 

Response.Write then calls .Write() on it's internal TextWriter object:

public void Write(object obj){ this._writer.Write(obj);}

HttpResponse also has a Property called Output that is of type, yes, TextWriter, so:

public TextWriter get_Output(){ return this._writer; }

Which means you can to the Response whatever a TextWriter will let you.  Now, TextWriters support a Write() method ala String.Format, so you can do this:

Response.Output.Write("Scott is {0} at {1:d}", "cool",DateTime.Now);

But internally, of course, this this is happening:

public virtual void Write(string format, params object[] arg){    this.Write(string.Format(format, arg)); } 

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.