Updated: April 2009
Encapsulates HTTP-response information from an ASP.NET operation.
Assembly: System.Web (in System.Web.dll)
The following methods of the class are supported only in postback scenarios and not in asynchronous postback scenarios:
Partial-page updates are enabled when you use UpdatePanel controls to update selected regions of a page instead of updating the whole page with a postback. For more information, see UpdatePanel Control Overview and Partial-Page Rendering Overview.
The following example draws three overlapping rectangles when the page is requested. The code begins by setting the ContentType property to image/jpeg, so that the entire page will be rendered as a JPEG image. The code then calls the Clear method to ensure that no extraneous content is sent with this response. Next, the code sets the BufferOutput property to true so that the page is completely processed before it is sent to the requesting client. Two objects used to draw the rectangles are then created: a Bitmap and a Graphics object. The variables created in the page are used as coordinates to draw the rectangles and a string that appears inside the largest rectangle.
When the three rectangles and the string that appears inside them are drawn, the Bitmap is saved to the Stream object that is associated with the OutputStream property and its format is set to JPEG. The code calls the Dispose and Dispose methods to release the resources used by the two drawing objects. Lastly, the code calls the Flush method to send the buffered response to the requesting client.
In code, the object is referred to by the keyword Response. For example, Response.Clear() refers to the HttpResponse.Clear method. The Page class has a property that is named Response that exposes the current instance of .
<%@ Page Language="VB" %> <%@ import Namespace="System.Drawing" %> <%@ import Namespace="System.Drawing.Imaging" %> <%@ import Namespace="System.Drawing.Drawing2D" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Private Sub Page_Load(sender As Object, e As EventArgs) ' Set the page's content type to JPEG files ' and clears all content output from the buffer stream. Response.ContentType = "image/jpeg" Response.Clear() ' Buffer response so that page is sent ' after processing is complete. Response.BufferOutput = True ' Create a font style. Dim rectangleFont As New Font( _ "Arial", 10, FontStyle.Bold) ' Create integer variables. Dim height As Integer = 100 Dim width As Integer = 200 ' Create a random number generator and create ' variable values based on it. Dim r As New Random() Dim x As Integer = r.Next(75) Dim a As Integer = r.Next(155) Dim x1 As Integer = r.Next(100) ' Create a bitmap and use it to create a ' Graphics object. Dim bmp As New Bitmap( _ width, height, PixelFormat.Format24bppRgb) Dim g As Graphics = Graphics.FromImage(bmp) g.SmoothingMode = SmoothingMode.AntiAlias g.Clear(Color.LightGray) ' Use the Graphics object to draw three rectangles. g.DrawRectangle(Pens.White, 1, 1, width - 3, height - 3) g.DrawRectangle(Pens.Aquamarine, 2, 2, width - 3, height - 3) g.DrawRectangle(Pens.Black, 0, 0, width, height) ' Use the Graphics object to write a string ' on the rectangles. g.DrawString("ASP.NET Samples", rectangleFont, SystemBrushes.WindowText, New PointF(10, 40)) ' Apply color to two of the rectangles. g.FillRectangle( _ New SolidBrush( _ Color.FromArgb(a, 255, 128, 255)), _ x, 20, 100, 50) g.FillRectangle( _ New LinearGradientBrush( _ New Point(x, 10), _ New Point(x1 + 75, 50 + 30), _ Color.FromArgb(128, 0, 0, 128), _ Color.FromArgb(255, 255, 255, 240)), _ x1, 50, 75, 30) ' Save the bitmap to the response stream and ' convert it to JPEG format. bmp.Save(Response.OutputStream, ImageFormat.Jpeg) ' Release memory used by the Graphics object ' and the bitmap. g.Dispose() bmp.Dispose() ' Send the output to the client. Response.Flush() End Sub 'Page_Load </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>ASP.NET Example</title> </head> <body> <form id="form1" runat="server"> </form> </body> </html>
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.