Code declaration blocks define member variables and methods to be compiled into the dynamically generated Page class that represents the ASP+ page.
<script runat=”server” [language=”codelanguage”] > Code goes here…. </script>
In addition, an external file containing script can be specified:
< script runat=”server” [language=”codelanguage”] [src=”externalfilename”] />
Code declaration blocks are defined using <script> tags that contain a runat attribute defined as “server”. The <script> tag may optionally utilize a language attribute to specify the language of its inner code. If none is specified, ASP+ will default to the language configured for the base page (controlled using the @ Page Directive).
The <script> tag may also optionally specify an external script file by defining a src attribute. When the src attribute is defined, all inner content within a <script runat=server> tag is ignored and the abbreviated form of the closing tag (/>)
is used rather than </script>.
The following example demonstrates how you could define event-handling logic for the EnterBtn_Click event.
<html> <script language="C#" runat="server"> void EnterBtn_Click(Object Src, EventArgs E) { Message.Text = "Hi " + Name.Text + ", welcome to ASP+!"; } </script> <body> <form runat="server"> Enter your name: <asp:textbox id="Name" runat=server/> <asp:button text="Enter" Onclick="EnterBtn_Click" runat="server"/> <p> <asp:label id="Message" runat=server/> </form> </body> </html>
See Also
ASP+ Page Syntax