ASP.NET
  Home arrow ASP.NET arrow Page 6 - ASP.NET and the .NET Framework
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

ASP.NET and the .NET Framework
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 38
    2005-03-16

    Table of Contents:
  • ASP.NET and the .NET Framework
  • ASP.NET
  • Visual Studio .NET
  • The ASP Version
  • Hello World Using Visual Studio .NET
  • Add two more HTML labels

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    ASP.NET and the .NET Framework - Add two more HTML labels


    (Page 6 of 6 )

    Now add two more HTML labels. To get to the next line on the design surface, click on the design surface outside the Hello World label and press the Enter key. The cursor will move to the next line.


    Figure 1-8.  Placing an HTML Label in Visual Studio .NET


    Figure 1-9.  Resizing an HTML label in Visual Studio .NET

    Drag another HTML Label control onto the design surface, change its text to ASP.NET Style, change its block format to Heading 1, and then resize it.

    Move to the next line and create one more HTML label with the words Using Visual Studio.NET. Set its block format to Heading 2 and resize it. When you are done, the screen should look something like Figure 1-10.


    Figure 1-10.  HTML labels in Visual Studio .NET

    Now it’s time to place a control that will display the date and time. To do this, move to the next line on the design surface by clicking on the design surface at the end of the last control and pressing Enter. Then click on the Web Forms button on the Toolbox.

    You are probably wondering about the differentiation between HTML controls and Web Forms controls. The reasons and details for this will fill the next several chapters. For now, suffice it to say that “classic” HTML controls are more resource-efficient, but the controls contained in the Web Forms toolbox allow for server-side processing.

    Drag a Label control onto the design surface. It will contain the text Label. If you look at the Properties Window, the object will have an ID of Label1.

    Look at the Solution Explorer on the right side of the screen. If the Solution Explorer is not visible, choose Solution Explorer from the View menu, or press Ctrl+Alt+L.

    Right-click on WebForm1.aspx and select View Code. A code window will appear where the design surface was. The tab at the top of the code window will be labeled WebForm1.aspx.cs*.

    If you are working in Visual Basic .NET, the tab will be labeled WebForm1.aspx.vb*. In either case, the asterisk indicates that the file has not yet been saved.

    Slide down the code window until you see the Page_Load method. In C#, this will look like:

      private void Page_Load(object sender, System.EventArgs e)
      {
         // Put user code to initialize the page here
      }

    In VB.NET, it will look like this:

      Private Sub Page_Load(ByVal sender As System.Object, _
                            ByVal e As System.EventArgs) 
                  Handles MyBase.Load
          'Put user code to initialize the page here
      End Sub

    Put your cursor at the end of the comment line (after the word here) and press the Enter key. This will move the cursor to the beginning of the next line, properly indented, ready to type. If you are working in C#, enter the following lines of code:

      Label1.Text = "The date and time is " +
        DateTime.Now.ToString( );

    If you are working in VB.NET, enter these lines of code:

      Label1.Text = "The date and time is " & _
           DateTime.Now.ToString( )

    When you type the period after Label1, you see a drop-down of all the possible methods and properties that are valid in this context. (If you don’t see the drop-down list, verify that the label name is spelled properly and, if using C#, that the casing is correct.) This is the IntelliSense technology at work.

    You can either scroll down and select the proper method or function by pressing Tab or any other key, or start typing the desired method or function to narrow the search. When you get to the desired selection, press Tab or any other key. The Tab key enters that selection into your code without your having to type the entire word; pressing any other key enters the selection into your code followed by the key you pressed.

    The completed Page_Load method in the code window should look like the following in C#:

      private void Page_Load(object sender, System.EventArgs e)
      {
        // Put user code to initialize the page here
        Label1.Text = "The date and time is " +
          DateTime.Now.ToString( );
      }

    It will look like this in VB.NET:

      Private Sub Page_Load(ByVal sender As System.Object, _
                            ByVal e As System.EventArgs)  
                              Handles MyBase.Load
        'Put user code to initialize the page here
        Label1.Text = "The date and time is " & _
         DateTime.Now.ToString( )
     End Sub

    Press F5 to run the web application. When either the C# or VB.NET version is run it will look like the browser shown in Figure 1-11.

     
    Figure 1-11.  Hello World in Visual Studio .NET

    Although the code is nearly identical between the two languages, there are some differences worth noting:

    • C# code is case-sensitive while VB.NET is not.

    • All C# statements must end with a semicolon.

    • While both languages mostly ignore whitespace outside of quotes, VB.NET statements cannot span multiple lines without using a line-continuation character (the underscore preceded by a space). C# statements can span multiple lines.

    You have now learned how to write an extremely simple ASP.NET web application. The remaining chapters will show you, in greater detail, how to develop rich, robust web applications using many of the controls and tools available from ASP.NET.

    * Because the Common Language Runtime translates all code to a common interactive language that is later complied to native code, .NET can, in principle, be implemented on Unix, Linux, Mac OS X, or any other operating system.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Good Article for beginnerHi This good article for asp.net beginner The .NET...
     

    Buy this book now. This article is excerpted from Programming ASP.NET by Jesse Liberty and Dan Hurwitz (O'Reilly, 2003; ISBN 0596004877). Check it out at your favorite bookstore today. Buy this book now.

    ASP.NET ARTICLES

    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT