Pages

Monday, May 27, 2013

what is formatted output in asp.net

Here Response.Write():to display only string and you can not display any other data type values like int,date,etc.Conversion(from one data type to another) is not allowed.
 whereas Response .Output .Write(): you can display any type of data like int, date ,string etc.,by giving index values.
Sample code:
protected void Button1_Click(object sender, EventArgs e)
{
 Response.Write ("hi good morning!"+"is it right?");//only strings are allowed        
 Response.Write("Scott is {0} at {1:d}", "cool", DateTime.Now);//this will give 
       //error(conversion is not allowed)
 Response.Output.Write("\nhi goood morning!");//works fine
 Response.Output.Write("Jai is {0} on {1:d}", "cool", DateTime.Now);//here the
       // current date will be converted into string and displayed
}

No comments:

Post a Comment