JScript .NET, Part IX: Code Behind: The Benefits of Code Behind - Doc JavaScript | WebReference

JScript .NET, Part IX: Code Behind: The Benefits of Code Behind - Doc JavaScript


JScript .NET, Part IX: Code Behind

The Benefits of Code Behind

Client-side .html files mix HTML and JavaScript code. The HTML portion serves as the presentation layer of the Web site. This layer includes GUI widgets such as forms, button, text boxes, menus, and banners. The JavaScript portion is responsible for the business logic. It usually includes event handlers and functions to handle the user's requests. The HTML portion is static, and is independent of the user's actions. The JavaScript portion, on the other hand, is dynamic and is dependent on the user's actions.

The .NET environment provides an alternate paradigm for server-side Web sites. The Code Behind concept calls for a separation between the presentation layer and the business logic. The static part is ASP.NET code, residing in the .aspx file. It includes ASP.NET controls such as ASP:TextBox and ASP:Label. The dynamic part is JScript code, residing in a separate .js file.

The integration of the .aspx and the .js files is a bit complex. The .js file is not just included in the .aspx file. You need to compile it first, and then let the .aspx file call methods from the derived binary dll.

Separating the JScript code from the ASP.NET code has several benefits. From the software engineering point of view, the code is better organized: every file is either 100% ASP.NET or 100% JScript .NET. Another benefit is that distributed development is easier with Code Behind. Since there are two separate files, the Web site graphic designer can work on the ASP.NET code, while the JScript hacker can program the business logic behind the scenes.

The advantage of Code Behind to you is that the .NET framework compiles your Code Behind automatically, whenever the ASP.NET page is displayed; assuming the JScript has not already been compiled, or has been changed since the last compilation. In this column, we choose to show you what's going on behind the scenes, and will teach you how to compile the Code Behind explicitly. In this way, you will better know what the Developer's Studio is doing when building a project.


Next: How to write the Code Behind of Hello World


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

URL: https://www.webreference.com/js/column115/2.html