Define application member variables, event handlers, and methods.
<script runat="server" language="language" src = "externalfile">
Code goes here....
</script>
- 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.
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 ).
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>
<script language="VB" runat=server>
Sub Application_OnStart ( )
' Application startup code goes here...
End Sub
Sub Session_OnStart ( )
' Session startup code goes here...
End Sub
Sub Session_OnEnd ( )
' Session cleanup code goes here...
End Sub
Sub Application_OnEnd ( )
' Application cleanup code goes here...
End Sub
Overrides Sub HandleError ( ErrorInfo as Exception )
' Application error occurs
End Sub
</script> |
|
C# |
VB |
ASP.NET Applications