ASP.NET Code
  Home arrow ASP.NET Code arrow Page 4 - ASP.NET Basics (part 1): Nothing But .Net
Iron Speed
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 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
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 CODE

ASP.NET Basics (part 1): Nothing But .Net
By: Harish Kamath (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 119
    2003-07-23

    Table of Contents:
  • ASP.NET Basics (part 1): Nothing But .Net
  • Checking Out The Menu
  • Building Blocks
  • Hard Choices
  • Command And Control
  • Naming Names
  • Linking Out
  • Putting The Pieces Together

  • 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
     
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    ASP.NET Basics (part 1): Nothing But .Net - Hard Choices
    (Page 4 of 8 )

    With the ASP.NET environment all loaded and ready for action, let's jump into some code without any further ado. Pop open your favourite text editor and copy the following lines of code into it:


    <%@ Page Language="C#" %>
    <
    html>
    <
    head>
    <
    title>HelloChoice!</title>
    </
    head>
    <
    body>
    <%
    // print some output
    Response.Write("Choice. The problem is choice.");
    %>
    </
    body>
    </
    html>

    Save the file on your hard drive as "choice.aspx" in a folder named (say) "ASPBasics". It is important to note here that all ASP.NET files must have the .aspx extension.

    Next, in order to view this page via the IIS Web server, you'll need to create a so-called "virtual directory" with the Internet Service Manager application and map it to the folder above. Call this virtual directory
    (say) "ASPBasics" as well.

    You should now be able to view the page created above by browsing to the URL http://localhost/ASPBasics/choice.aspx in your browser (in case you named the script or directory differently, or if your Web server is accessible by a name other than "localhost", you should make the appropriate changes to this URL). Here's what you should see:

    Let's take a closer look at the code:


    <%@ Page Language="C#" %>

    This is the all-important "Page" directive, which must appear at the top of your ASP.NET program. Among other things, this directive is used to indicate the programming language used within the page. The default language for ASP.NET is VB.NET; however, I've chosen C# instead, for a number of different reasons:

    1. It's the language specially developed for the .NET Framework;

    2. It's completely object-oriented, thereby making it cleaner, easier to understand and a lot more fun to program in;

    3. For VB developers, there is no "unlearning" required (most VB programmers would have to unlearn quite a few concepts before jumping on the VB.NET bandwagon);

    4. I've always, always wanted to program in a language with a # in its name.

    One way to include a block of C# code is to enclose it within <%...%> tags (similar to ASP and PHP code), like this:


    <%
    ... 
    some C# code ...
    %>

    You can also use the <script> element to include C# code - that's demonstrated in the next example.

    So where's the C# code that I'm harping on, anyway?


    <%
    // print some output
    Response.Write("Choice. The problem is choice.");
    %>

    As you might have guessed, this line of code simply outputs a line of text to the browser. Instead of "hello world", I decided to use a line from the latest installment of "The Matrix" trilogy. In case you haven't heard about "The Matrix"...it's a deeply-existential film about how the entire world is an illusion created by machines, humans are actually batteries powering the system, and a hero will rise to save us all from our fate. Woohoo!

    OK, enough of the geek impersonation. Back to business...

    Wanna have some fun? Remove the semi-colon from the end of the line in the example above and reload it in the browser. You should see the following ugly error message:

    Yup, life in the .NET world is pretty rigid. But hey, it gets better from here!

    More ASP.NET Code Articles
    More By Harish Kamath (c) Melonfire


     

    ASP.NET CODE ARTICLES

    - How to Use the ListBox Control in ASP.NET 2.0
    - How to Load XML Documents in ASP.NET 2.0
    - DataGrid Code
    - ASP.NET Guestbook
    - User Controls and Client Side Scripting
    - ASP.NET Programming with Microsoft's AS...
    - ASP.NET Basics (part 3): Hard Choices
    - ASP.NET Basics (part 2): Not My Type
    - ASP.NET Basics (part 1): Nothing But .Net
    - Directory Tree Browser
    - How to get the confirmation of Yes/No from a...
    - Complete example using custom errors and wri...
    - Paging Certain # records per page .NET style
    - General Methods of formatting and Subtractin...
    - .NET LinkButton web control

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




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