asp.net.ph

Skip Navigation Links

Code Declaration Blocks — global.asax


Define application member variables, event handlers, and methods.

<script runat="server" language="language" src = "externalfile">
   Code goes here....
</script>

Parameters

language
The language used in the current code declaration block. Can be C#, Visual Basic, or JScript.
externalfile
The name of a file containing code that is loaded and used in the current code declaration block.

Remarks

Code declaration blocks are defined using <script> tags that contain a runat="server" attribute/value pair. The script tag may optionally utilize a "language" attribute to specify the language of its inner code. If none is specified, ASP.NET will default to the language configured for the application ( specified in the application’s XML configuration file ).

Syntax Example

The below example demonstrates how a <script runat=server> block can be used within an ASP.NET application file to define four event handlers.

<script language="C#" runat=server>
   void Application_OnStart ( ) {
      // Application startup code goes here...
   }
   void Session_OnStart ( ) {
      // Session startup code goes here...
   }
   Sub Session_OnEnd ( ) {
      // Session cleanup code goes here...
   }
   Sub Application_OnEnd ( ) {
      // Application cleanup code goes here...
   }
   Overrides Sub HandleError ( ErrorInfo as Exception ) {
      // Application error occurs
   }
</script>
  C# VB

See Also

ASP.NET Applications



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note