Forums » .NET » ASP.NET »

Differentiate Response. write & Response.output.write?


Posted Date: 30 Mar 2005      Posted By:: Gnanesh Babu S G     Member Level: Gold    Member Rank: 0     Points: 2   Responses: 8



Differentiate Response. write & Response.output.write?



Responses

#14604    Author: Ravindra Sadaphule      Member Level: Bronze      Member Rank: 0     Date: 30/Mar/2005   Rating: 2 out of 52 out of 5     Points: 2

The respose.write just outputs a string to webpage. Response.Output.Write formats the string as per specified options before writing to the the webpage.

 
#14610    Author: Satty      Member Level: Gold      Member Rank: 0     Date: 30/Mar/2005   Rating: 2 out of 52 out of 5     Points: 2

hey

The difference between Response.Write() and Response.Output.Write() in ASP.NET. The short answer is that the latter gives you String.Format-style output and the former doesn't. The long answer follows.

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));
}


Satty


 
#14640    Author: www.DotNetVJ.com      Member Level: Gold      Member Rank: 27     Date: 30/Mar/2005   Rating: 2 out of 52 out of 5     Points: 2

visit this interview exam link in dotnetspider.

http://www.dotnetspider.com/technology/exams/ShowExamQuestion.aspx?ExamQuestionId=868

in simple way

Response.write - it writes the text stream
Response.output.write - it writes the HTTP Output Stream.

--Vj

Thanks -- Vijaya Kadiyala
http://www.DotNetVJ.com
Microsoft MVP





 
#47644    Author: jayender      Member Level: Bronze      Member Rank: 0     Date: 12/Apr/2006   Rating: 2 out of 52 out of 5     Points: 2

Check this:
http://www.hanselman.com/blog/Permalink.aspx?guid=873bc510-8fce-45c4-9e57-8437166e08b4


 
#92354    Author: jagadish      Member Level: Bronze      Member Rank: 0     Date: 09/Nov/2006   Rating: 2 out of 52 out of 5     Points: 2

Response.write prints the result string
response.output.write writes the results in desired format


 
#153388    Author: Vijayaragavan.R      Member Level: Bronze      Member Rank: 0     Date: 24/Sep/2007   Rating: 2 out of 52 out of 5     Points: 2

Response.Output.Write() gives you String.Format-style formatted output and the Response.Write() doesn't.

FOR Example
Response.Write("Current Date Time is "+DateTime.Now.ToString());

Response.Output.Write("{0} is {1:d}", "Current Date Time is: ",DateTime.Now);


 
#268136    Author: Kumar Velu      Member Level: Gold      Member Rank: 122     Date: 22/Jul/2008   Rating: 2 out of 52 out of 5     Points: 6

The difference between Response.Write() and Response.Output.Write() in ASP.NET. The short answer is that the latter gives you String.Format-style output and the former doesn't. The long answer follows.

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));
}


 
#286155    Author: RobinHood      Member Level: Gold      Member Rank: 44     Date: 25/Aug/2008   Rating: 2 out of 52 out of 5     Points: 5

Difference..
Resopnse.Output.Write..
1.Formatted output will be displayed.
2.It gives String.Format-style formatted output.
3.It writes the HTTP Output Stream.
4.As per specified options it formats the string and then write to web page.

Response.Write..
1.unformatted output will be displayed.
2.It never gives like that.
3.It writes the text stream
4.It just output a string to web page.

Regards
Sridhar R
Nothing is illegal, Until You Get Caught


 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Return to Discussion Forum
Start new thread

Subscribe to Subscribers
Awards & Gifts
Talk to Webmaster Tony John

Online Members

Priya jain
More...
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India