JScript .NET, Part IX: Code Behind: Hello World's ASP.NET Page - Doc JavaScript | WebReference

JScript .NET, Part IX: Code Behind: Hello World's ASP.NET Page - Doc JavaScript


JScript .NET, Part IX: Code Behind

Hello World's ASP.NET Page

Let's look now at the ASP.NET page for our Hello World application. We used the ASP:Label control to display the message on the screen. Here is the .aspx file (helloworld.aspx):

<%@ Page LANGUAGE="JScript" SRC="helloworld.aspx.js"
  INHERITS="ASPPlus.codeBehind" %>
<HTML>
<HEAD>
  <TITLE>Hello World Test</TITLE>
</HEAD>
<BODY STYLE="font-size:12;
  font-family:arial,verdana,sans-serif;">
  <FORM RUNAT="server">
  <P ALIGN="center"><ASP:LABEL ID="message" RUNAT="server">
  </ASP:LABEL></P>
  </FORM>
</BODY>
</HTML>

The first line includes directives. It specifies the scripting language (LANGUAGE="JScript"), the codebehind file (SRC="helloworld.aspx.js"), and the class name to inherit from (INHERITS="ASPPlus.codeBehind"). The Web server looks for the class definition of ASPPlus.codeBehind, as specified by the INHERITS attribute. ASPPlus is the namespace, or the package in JScript .NET terms. codeBehind is the name of the class, as we have defined in helloworld.aspx.js (see Page 3). The Web server looks for the binary representation of the ASPPlus.codeBehind class in all dll files included in the bin directory underneath the current working directory of the ASP.NET page (helloworld.aspx). If the Web server does not find this class, it will generate the dll file from the code specified by the SRC attribute.

The content of the ASP.NET page is straightforward. We have one ASP.NET control, ASP:Label. Its important attribute is its ID, message. We set the message's Text property to the Hello World greeting, and in this way display this greeting on the screen.

Sometimes, using Code Behind is too complicated for a simple task. You can put your JScript .NET code in the ASP.NET page directly. Here is the Hello World application in one piece, for your reference:

<%@ Page LANGUAGE="JScript" %>
<HTML>
<HEAD>
  <TITLE>Hello World Test</TITLE>
<SCRIPT LANGUAGE="JScript" RUNAT="server">
public function Page_Load(sender:Object, E:System.EventArgs)
  : void {
  message.Text = "Hello World, Code Behind";
}
</SCRIPT>
</HEAD>
<BODY STYLE="font-size:12; font-family:arial,verdana,sans-serif;">
  <FORM RUNAT="server">
  <P ALIGN="center"><ASP:LABEL ID="message" RUNAT="server">
  </ASP:LABEL></P>
  </FORM>
</BODY>
</HTML>

As you can see, the principles are the same. The Page_Load() function is invoked automatically when the page loads. It sets the Text property of the message ID to "Hello World, Code Behind". This ASP.NET file is self-sufficient, and you don't need to import any classes.


Next: How to write the Code Behind of add consumer


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: July 29, 2002
Revised: July 29, 2002

URL: http://www.webreference.com/js/column115/4.html