Logo

Navigation
  • Home
  • Services
    • ERP Solutions
    • Implementation Solutions
    • Support and Maintenance Solutions
    • Custom Solutions
    • Upgrade Solutions
    • Training and Mentoring
    • Web Solutions
    • Production Support
    • Architecture Designing
    • Independent Validation and Testing Services
    • Infrastructure Management
  • Expertise
    • Microsoft Development Expertise
    • Mobile Development
    • SQL Server Database and BI
    • SAP BI, SAP Hana, SAP BO
    • Oracle and BI
    • Oracle RAC
  • Technical Training
    • Learn Data Management
      • Business Intelligence
      • Data Mining
      • Data Modeling
      • Data Warehousing
      • Disaster Recovery
    • Learn Concepts
      • Application Development
      • Client Server
      • Cloud Computing Tutorials
      • Cluster Computing
      • CRM Tutorial
      • EDI Tutorials
      • ERP Tutorials
      • NLP
      • OOPS
      • Concepts
      • SOA Tutorial
      • Supply Chain
      • Technology Trends
      • UML
      • Virtualization
      • Web 2.0
    • Learn Java
      • JavaScript Tutorial
      • JSP Tutorials
      • J2EE
    • Learn Microsoft
      • MSAS
      • ASP.NET
      • ASP.NET 2.0
      • C Sharp
      • MS Project Training
      • Silverlight
      • SQL Server 2005
      • VB.NET 2005
    • Learn Networking
      • Networking
      • Wireless
    • Learn Oracle
      • Oracle 10g
      • PL/SQL
      • Oracle 11g Tutorials
      • Oracle 9i
      • Oracle Apps
    • Learn Programming
      • Ajax Tutorial
      • C Language
      • C++ Tutorials
      • CSS Tutorial
      • CSS3 Tutorial
      • JavaScript Tutorial
      • jQuery Tutorial
      • MainFrame
      • PHP Tutorial
      • VBScript Tutorial
      • XML Tutorial
    • Learn Software Testing
      • Software Testing Types
      • SQA
      • Testing
  • Career Training
    • Career Improvement
      • Career Articles
      • Certification Articles
      • Conflict Management
      • Core Skills
      • Decision Making
      • Entrepreneurship
      • Goal Setting
      • Life Skills
      • Performance Development
      • Personal Excellence
      • Personality Development
      • Problem Solving
      • Relationship Management
      • Self Confidence
      • Self Supervision
      • Social Networking
      • Strategic Planning
      • Time Management
    • Education Help
      • Career Tracks
      • Essay Writing
      • Internship Tips
      • Online Education
      • Scholarships
      • Student Loans
    • Managerial Skills
      • Business Communication
      • Business Networking
      • Facilitator Skills
      • Managing Change
      • Marketing Management
      • Meeting Management
      • Process Management
      • Project Management
      • Project Management Life Cycle
      • Project Management Process
      • Project Risk Management
      • Relationship Management
      • Task Management
      • Team Building
      • Virtual Team Management
    • Essential Life Skills
      • Anger Management
      • Anxiety Management
      • Attitude Development
      • Coaching and Mentoring
      • Emotional Intelligence
      • Stress Management
      • Positive Thinking
    • Communication Skills
      • Conversation Skills
      • Cross Culture Competence
      • English Vocabulary
      • Listening Skills
      • Public Speaking Skills
      • Questioning Skills
    • Soft Skills
      • Assertive Skills
      • Influence Skills
      • Leadership Skills
      • Memory Skills
      • People Skills
      • Presentation Skills
    • Finding a Job
      • Etiquette Tips
      • Group Discussions
      • HR Interviews
      • Interview Notes
      • Job Search Tips
      • Resume Tips
      • Sample Resumes
 

ASP.NET Code Directory

By Exforsys | on August 12, 2005 |
ASP.NET 2.0

ASP.NET Code Directory

In this tutorial you will having a deeper look at the Code Directory, the Code Beside Model and the evolution of the Code Behind model, learn about Partial Classes, Sharing Source components, Creating a Component, you will learn how to create a Application_Code folder, to create a component in the Application_Code folder and use a component.

 

Having a deeper look at the Code Directory

As mentioned in the earlier section of this tutorial the Code directory is one of the significant folders of the ASP.NET application. It contains the reusable components that are automatically compiled and linked to the page code by the runtime engine. Visual Studio 2005 gives a lot of importance to the monitoring of this directory. The components are compiled by default into a single assembly and referenced in the project. The assembly is then made available to all the pages in the site.

The Code Beside Model and the evolution of the Code Behind model

The Code Behind class model has been evolved to get round the problems of using inline code in Visual Studio 2003. Using inline code automatically deprived the user of the benefits of the IntelliSense. The Visual Studio 2003 model is based on the idea that each Web form page is bound to a separate class file and this file is the basis of the dynamically generated page class that the ASP.NET runtime creates for each .aspx resource. All server code is channelled to the code behind class and everything compiles down to an assembly in which all the constituent classes are packed together. This becomes a handicap. An explicit step by step compilation is demanded. Every page must reference the code behind class through a src, else it will not be compiled. The AppDomain has to be restarted with every change and the timestamp of the directory is modified. If the project is large, the whole process is expensive.

ASP.NET 2.0 offers the compile on demand feature to the users. All resources are compiled only on demand with an exception of a few file types which are dynamically compiled. ASP.NET pages, Web Services, user controls, HTTP handlers and global.asax are dynamically compiled on demand. Any changes to the compiled copy is automatically detected and the copy is invalidated and a fresh compilation takes into account the changes. This reduces the process overhead for developers and helps in rapid application development.

The compile on demand feature has been extended to a number of file types in ASP.NET 2.0. Class files, resource files, Web service discovery files, and typed DataSet schema files have all acquired this capability. All changes to files are promptly and automatically detected and no development tool is required to force the compile step. It becomes possible to refine the whole code behind mechanism. Since ASP.NET is backward compatible it works with the code beside schema of older applications with ease.

The code beside model provides for a modular approach by separating support code and layout. It comes with a page/class association and uses a different set of keywords and behaviours. By default the code is stored inline. To take advantage of the code separation the user has to select a template by selecting Add New Item form the Website menu. The pages can be edited with page separation and the code is stored in a class file specified through the CompileWeb attribute. ASP.NET then compiles the page when requested.

Partial Classes

The page separation feature enables developers take advantage of partial classes. The CompileWeb attribute in the @Page directive is used to find the file containing the code. The .aspx page and the code page are then dynamically merged into a single class that inherits the base page class. This is then compiled into an assembly and executed. By default the code in the code beside file is located in the ASP namespace and contains only the class definition which is partial. It however contains the event handlers and other custom code that the user writes. The ASP.NET 2.0 runtime parses the .aspx layout file and combines the information of the partial class in the code beside file. The class then inherits from the Page and is compiled and served on request. The code beside version of our ‘Hello world’ application would look like this:

using System;
namespace ASP
………………{
……………….public partial class Helloworld
……………………..{
………………………void Send_Greeting(object sender, EventArgs e)
…………………………….{
………………………………MsgSent.Text=Greet.Text;
……………………………..}
……………………….}
……………….}

Sharing Source components

The compile on demand feature has been extended to the classes bound to the Web page in the code beside model. The helper components or other class files of the application can now be stored in the Code subdirectory. Visual Studio 2005 monitors the directory and compiles all class files that are added there. This enables the assembly to be referenced automatically after compilation. This assembly is named code.dll and has application scope. It is created in the Temporary ASP.NET files folder outside the Web application space.

To illustrate this concept let us create a simple project. To recall the steps for creating a new web site:

1. Open Visual Web Developer.

2. On the File menu, click NewWeb Site.

3. The New Web Site dialog box appears.

4. Under Visual Studio installed templates, click ASP.NET Web Site.

5. In the Location box, enter the name of the folder where you want to keep the pages of your Web site.

6. For example, type the folder name C:WebSites.

7. In the Language list, select C#.

8. Click OK.

Visual Web Developer creates the folder and a new page named Default.aspx.

Creating a Component

Reusable components can be created by keeping them in a sub directory. Let us call this directory App_code. This directory is monitored by ASP.NET 2.0 and all components added to this directory are compiled automatically into a single assembly.

To create a Application_Code folder

1. In Solution Explorer, right-click the name of the Web site, and select Add

2. Select the folder Application_Code.

3. A component can now be added to the site.

.

.

To create a component in the Application_Code folder

1. In Solution Explorer, right-click the Application_Code folder, and then click Add New Item.

2. Under Visual Studio installed templates, choose Class.

3. Name the class ExForSysClass1.

4. From the Language list, select C#.

5. Click Add.

Visual Web Developer opens the new class file in the editor.

1. Create a class that has a single property named testString.

public class ExForSysClass1
{
……….public ExForSysClass1() {}
……….private string testStringValue;
……….public string testString
……….{
………………..
get
………………..{
…………………………
return testStringValue;
………………..}
………………..
set
………………..
{
…………………………
testStringValue = value;
………………..
}
……….
}
}

2. Save the file and close it.

Using the Component

1. Create a file called ExForSys.aspx

2. From the Standard folder of the toolbox, drag a TextBox control, Label control, and Button control onto the page.

3. Double-click the button to create a Click handler it.

4. In the handler, type in the code just below the page directive.

< script runat="server" language=C# >
……….void Button1_Click(object sender, EventArgs e)
……….{
………………..ExForSysClass1 Test = new ExForSysClass1();
…………………………Test.testString=TextBox1.Text;
………………………………….Label1.Text=Test.testString;
……….}
< / script >

5. When you enter a space after New or new, Visual Web Developer displays a list of available classes. The class you created earlier, ExForSysClass1, appears in the drop-down list.

Testing the Page and Component

1. Press CTRL+F5 to run the page.

2. When the page appears in the browser, enter something into the text box and click the button. Doing so sets a property in your simple class, which is then displayed in the Label control.

Navigate to Windows Explorer and examine the directory in which the Website is located. Note that the page App_code directory and the .aspx files appear in the website folder. Also note that the .dll file is not present in the directory. ASP.NET has compiled the page and the component dynamically.

« « Creating an ASP.NET Application
ASP.NET Page Object Model » »

Author Description

Avatar

Editorial Team at Exforsys is a team of IT Consulting and Training team led by Chandra Vennapoosa.

Free Training

RSSSubscribe 392 Followers
  • Popular
  • Recent
  • ASP.NET State Management And Caching

    August 30, 2005 - 0 Comment
  • Whats New in ASP.NET 2.0

    August 11, 2005 - 0 Comment
  • ASP.NET Adding Sorting and Paging in GridView

    September 10, 2005 - 0 Comment
  • Application Development in .NET

    November 21, 2007 - 0 Comment
  • ASP.NET Security

    September 2, 2005 - 0 Comment
  • Creating an ASP.NET Application

    August 11, 2005 - 0 Comment
  • ASP.NET DataBound Controls – Details View

    September 13, 2005 - 0 Comment
  • What’s New in the .NET Framework 2.0 ?

    July 26, 2005 - 0 Comment
  • Forms Authentication in ASP.NET

    September 2, 2005 - 0 Comment
  • ASP.NET Page Object Model

    August 14, 2005 - 0 Comment
  • Application Development in .NET

    November 21, 2007 - 0 Comment
  • ASP.NET Advanced Site Functionality

    September 16, 2005 - 0 Comment
  • ASP.NET : Dynamic Image control

    September 16, 2005 - 0 Comment
  • ASP.NET Creating Web Wizards

    September 16, 2005 - 0 Comment
  • Displaying Master-Detail Data on Separate Pages in ASP.NET

    September 16, 2005 - 0 Comment
  • ASP.NET Displaying Master-Detail Data on the Same Page

    September 13, 2005 - 0 Comment
  • ASP.NET DataBound Controls – Details View

    September 13, 2005 - 0 Comment
  • ASP.NET Using a Grid to Display Detail Information

    September 13, 2005 - 0 Comment
  • ASP.NET Adding Sorting and Paging in GridView

    September 10, 2005 - 0 Comment
  • ASP.NET GridView Filtering

    September 10, 2005 - 0 Comment

Exforsys e-Newsletter

ebook
 

Related Articles

  • Application Development in .NET
  • ASP.NET Advanced Site Functionality
  • ASP.NET : Dynamic Image control
  • ASP.NET Creating Web Wizards
  • Displaying Master-Detail Data on Separate Pages in ASP.NET

Latest Articles

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies
  • Sitemap
  • Privacy Policy
  • DMCA
  • Trademark Information
  • Contact Us
© 2023. All Rights Reserved.IT Training and Consulting
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT