aspxtreme

Code Declaration Blocks

ASP.NET Syntax   ASP.NET Page Syntax


Defines member variables and methods compiled in the dynamically generated Page or UserControl classes that represent the ASP.NET page and user control, respectively.

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

Attributes


language Specifies the language used in this code declaration block. This value can represent any .NET-compatible language, such as Visual Basic ( VB ), C#, or JScript.NET. If no language is specified, this value defaults to that specified in the @ Page directive. If no language is specified in the directive, the default is VB.
src Specifies the path and file name of a script file to load. When this attribute is used, any other code in the declaration block is ignored.

Remarks

Code declaration blocks are defined using <script> tags that contain a runat attribute value set to "server". The <script> element can optionally use a language attribute to specify the language of its inner code. If none is specified, ASP.NET defaults to the language configured for the base page or user control ( controlled using the @ Page and @ Control directives ).

You can also use the <script> element to specify an external script file by using the src attribute. When you define the src attribute, all content between the opening and closing tags of the <script> element is ignored. In this case, use a closing slash at the end of the opening tag. For example, <script runat="server" src="myFile.cs" /> .

Syntax Example

The below code snippet demonstrates how you can 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.NET!";
   }
</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>
  C# VB

See Also

Introduction to Web Forms



Books and more ...


Suggested Reading

Need a break ?



Previous page Back to top Next page

Check out related books at Amazon

© 2000-2008 Rey Nuñez All rights reserved.

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

You can help support aspxtreme