C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » ASP.NET/Web Applications »

Difference between Response.Write and Response.Output.Write


Posted Date: 27 Dec 2007    Resource Type: Articles    Category: ASP.NET/Web Applications
Author: Vadivel MohanakrishnanMember Level: Diamond    
Rating: 1 out of 5Points: 10



Introduction



From classical ASP days if we want to print some string with formatting we used to make use of Response.Write and some function to do the string formatting for us. But in .NET we have Response.Output.Write which is equal to Response.Write + String.Format features.

Find below the basic sample explaining this feature!



private void Page_Load (object sender, System.EventArgs e)
{
DateTime dtTwoDays = DateTime.Now; // Get the current date
dtTwoDays = dtTwoDays.AddDays(2); // Add 2 days to it

Response.Write(”Classical way of doing the same thing”);

string strMessage = dispMessage(dtTwoDays); // Call a method which would return the formatted string.
Response.Write(strMessage); // Print that formatted string

Response.Write(”.NET way of doing the same thing:”);
Response.Output.Write(”{0} from today is {1:d}”, “Two days”, dtTwoDays);
}

Private string dispMessage(DateTime dtMVP)
{
// {0} and {1:d} are the place holders which would take up the values passed as parameters
// {0} will take “Two days“ and
// {1:d} will take the value of dtMVP
return String.Format(”{0} from today is {1:d}”, “Two days”, dtMVP);
}

Summary



While using this code don't forget to include “BR” tags where ever necessary. So that the output would be well formatted. If not, everything would be printed in a single line. Hope this helps!



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Response.Write and Response.Output.Write  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to handle Listbox's updated items index with out control's back
Previous Resource: Draw Signature or images in Asp.net Web Page
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET/Web Applications


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use