This documentation is archived and is not being maintained.
TemplateControl.OnError Method
.NET Framework 1.1
Raises the Error event.
[Visual Basic] Protected Overridable Sub OnError( _ ByVal e As EventArgs _ ) [C#] protected virtual void OnError( EventArgs e ); [C++] protected: virtual void OnError( EventArgs* e ); [JScript] protected function OnError( e : EventArgs );
Parameters
- e
- An EventArgs object that contains the event data.
Example
[Visual Basic, C#] The following example demonstrates a possible use of the method OnError. It creates a string with some invalid arguments, which leads to an exception. Notice that since TemplateControl is abstract, this sample has been written using the Page class, which derives from it.
[Visual Basic] <%@ Page language="VB" %> <html> <head> <script language="VB" runat="server"> Sub Page_Load( sender as object, e as System.EventArgs) AddHandler Page.Error, AddressOf Error_Handler try Dim myString as string = "Hello" 'An exception is raised as the length of 'myString' is less than '6'. Dim mySubString as string= myString.Substring(0,6) catch e1 As Exception OnError (EventArgs.Empty) End try End Sub Sub Error_Handler( sender as object,e as System.EventArgs ) Response.Write("<br><b>An Error was raised</b>") End Sub </script> </head> </html> [C#] <%@ Page language="c#" %> <html> <head> <script language="C#" runat="server"> void Page_Load(object sender, System.EventArgs e) { Page.Error += new System.EventHandler(Error_Handler); try { string myString = "Hello"; // An exception is raised as the length of 'myString' is less than '6'. string mySubString = myString.Substring(0,6); } catch(Exception) { OnError(EventArgs.Empty); } } void Error_Handler(object sender,System.EventArgs e) { Response.Write("<br><b>An Error was raised</b>"); } </script> </head> </html>
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
TemplateControl Class | TemplateControl Members | System.Web.UI Namespace
Show: