Page.Context Property
.NET Framework 2.0
Gets the HttpContext object associated with the page.
Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)
Assembly: System.Web (in system.web.dll)
The following code example uses the Context property to access the HttpContext.AddError and HttpContext.ClearError methods and the HttpContext.AllErrors property. The example creates three custom exceptions using the AddError method and uses the AllErrors property to load these exceptions to an array. It then writes the array to the containing page and uses the ClearError method to clear all the errors from the Context property.
void Page_Load(Object sender,EventArgs e) { Response.Write("<h3>Page.Context Example:</h3>"); // Add three custom exceptions. Context.AddError(new Exception("<font color='red'><h3>New Exception #1.</h3>")); Context.AddError(new Exception("<font color='red'><h3>New Exception #2.</h3>")); Context.AddError(new Exception("<font color='red'><h3>New Exception #3.</h3>")); // Capture all the new Exceptions in an array. Exception[] errs = Context.AllErrors; foreach (Exception ex in errs) { Response.Write("<center><b>" + Server.HtmlEncode(ex.ToString()) + "</b></center><br>"); } // Clear the exceptions so ASP.NET won't handle them. Context.ClearError(); }
void Page_Load(Object sender,System.EventArgs e)
{
get_Response().Write("<h3>Page.Context Example:</h3>");
// Add three custom exceptions.
get_Context().AddError(new Exception
("<font color='red'><h3>New Exception #1.</h3>"));
get_Context().AddError(new Exception
("<font color='red'><h3>New Exception #2.</h3>"));
get_Context().AddError(new Exception
("<font color='red'><h3>New Exception #3.</h3>"));
// Capture all the new Exceptions in an array.
System.Exception errs[] = get_Context().get_AllErrors();
for (int iCtr=0;iCtr<errs.length;iCtr++) {
System.Exception ex = errs[iCtr];
get_Response().Write("<center><b>"
+ get_Server().HtmlEncode(ex.ToString())
+"</b></center><br>");
}
// Clear the exceptions so ASP.NET won't handle them.
get_Context().ClearError();
}//Page_Load
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.