Hello ASP.NET

I l @ ve RuBoard

Typically, I tend to stay away from any particular IDE because such conversations can lead to an all out religious war. However, when it comes to building ASP.NET applications, Visual Studio .NET (VS.NET) fits the bill rather well. With the release of VS.NET, all development can take place in a single, familiar IDE. Application development in VB.NET, C#, MC++, FoxPro, and of course ASP.NET is now hosted in a single fully-integrated IDE. As such, Intellisense is now available to the ASP.NET developer. I don't know about you, but I'm starting to really rely on Intellisense.

To create the Hello ASP.NET sample, launch VS.NET and start a new Web Application. Figure 4.1.2 shows the New Project dialog with the ASP.NET Web Application icon selected. The dialog with provide the default project name "WebApplication." For now, just leave the project named as is. When generated, the name of the project should be WebApplication1 .

Figure 4.1.2. VS.NET New Project dialog box.

graphics/0401fig02.gif

After VS.NET has created the new Web project, you should open the IIS manager and view the structure and files created by VS.NET. Figure 4.1.3 shows the IIS Manager explorer. The WebApplication1 created by VS.NET is expanded to show the extent of the generated framework provided by the VS.NET project for a new Web Application.

Figure 4.1.3. IIS Manager.

graphics/0401fig03.gif

Contained within the WebApplication1 folder, exists VS.NET project files, * .csproj , along with the ASPX page, and the C# code for the ASP.NET page. ASPX pages consist of two parts , the HTML and the source page ”in our case, the .cs file. This separation of UI and business logic is essential to all application development and the ASP.NET team certainly did not overlook this detail.

Of the files created for the ASP.NET application, the main ones of interest at this point are

  • WebForm1.aspx The ASP page to be requested by the client browser.

  • WebForm1.asxp.cs The C# code used to implement any business logic for the aspx page.

  • Web.config An XML configuration file. ASP.NET allows for easy administration through this simple XML-based file.

When browsing the Solution Explorer in VS.NET, you'll notice that the WebForm1.aspx.cs file does not appear. To view the "code behind" page for WebForm1.aspx , you need to select the View Code option from the context menu. When right-clicking the WebForm1.aspx file within the Solution Explorer window, you should see something similar to Figure 4.1.4.

Figure 4.1.4. The solution explorer.

graphics/0401fig04.gif

To get things going, drag a label control onto the WebForm1.aspx design surface and set the properties shown in Figure 4.1.5.

Figure 4.1.5. Label Properties.

graphics/0401fig05.gif

To view the HTML code for the WebForm1.aspx page, select View HTML Source from the context menu.

 1: <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" graphics/ccc.gif Inherits="WebApplication2.WebForm1" %>  2: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >  3: <HTML>  4:    <HEAD>  5:            <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">  6:            <meta name="CODE_LANGUAGE" Content="C#">  7:            <meta name="vs_defaultClientScript" content="JavaScript (ECMAScript)">  8:            <meta name="vs_targetSchema" content="http://schemas.microsoft.com/ graphics/ccc.gif intellisense/ie5">  9:    </HEAD> 10:    <body MS_POSITIONING="GridLayout"> 11:           <form id="Form1" method="post" runat="server"> 12:                  <asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 33px; POSITION: graphics/ccc.gif absolute; TOP: 108px" runat="server">Hello ASP.NET</asp:Label> 13:           </form> 14:    </body> 15: </HTML> 

With the label properties set, build and execute the Web Application project; this can be done by pressing F5. The first time the aspx page is requested from IIS, it will be compiled and an assembly, WebApplication1.dll in this case, will be created and placed in the bin directory. On subsequent requests , IIS will check to ensure that the dll is up to date and either use the compiled assembly or compile again if the source has changed.

The single largest benefit of ASP.NET and VS.NET is the ability to debug! an ASPX Web Application using the VS.NET debugger. View the code for WebForm1.aspx and locate the following code segment:

 1: private void Page_Init(object sender, EventArgs e) 2: { 3:     // 4:     // CODEGEN: This call is required by the ASP.NET Web Form Designer. 5:     // 6:     InitializeComponent(); 7: } 

Place a break point on the InitializeComponent statement. A break point can be placed by using the F9 key. With the break point in place, as depicted in Figure 4.1.6, press F5 to launch the Web Application project and you should see IE start up. Control will then transfer to the VS.NET Debugger when the Page_Init method is invoked and the break point on line 6 is reached.

Figure 4.1.6. Debugging ASP.NET.

graphics/0401fig06.gif

Developers who are already familiar with previous versions of Microsoft Visual Studio will be right at home when developing ASP.NET applications. Before .NET and VS.NET, the process of debugging an ASP-based application was similar to sliding down a sharp razor into a vat of alcohol.

I l @ ve RuBoard


C# and the .NET Framework. The C++ Perspective
C# and the .NET Framework
ISBN: 067232153X
EAN: 2147483647
Year: 2001
Pages: 204

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net