ASP.NET Code
  Home arrow ASP.NET Code arrow Page 6 - 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

    Free Web 2.0 Code Generator! Generate data entry 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 - Naming Names
    (Page 6 of 8 )

    Let's move on to variables. Variables are the bread and butter of every programming language...and ASP.NET has them too. A variable can be thought of as a programming construct used to store both numeric and non-numeric data; this data can then be used in different places in your C# code.

    The .NET Framework and all its programming languages - C#, VB.NET, Jscript.NET et al - support a number of different variable types: integers, floating point numbers, strings and arrays. Unlike some scripting languages, which can automatically determine variable type based on the data it holds, .NET languages require you to explicitly define the type of each variable before using it.

    Every variable must have a name - this name is used to refer to the variable, to perform operations on it, and to retrieve the data it contains. In C#, a variable name is preceded by a keyword indicating the variable type, and must begin with a letter, optionally followed by more letters and numbers. Variable names are case-sensitive, and reserved keywords cannot be used as variable names. For example, "popeye", "one_two_three" and "bigPirateShip" are all valid variable names, while "byte" and "123" are invalid variable names.

    The following example demonstrates how variables can be used in a ASP.NET
    document:


    <script language="c#" runat="server">
    void Page_Load()

    string name// define a variable as a string type
    name "Neo"// put some initial value into it

    whoami.Text "I am " name ". Welcome to my world.";

    </script>
    <html>
    <head><title>Who am I?</title></head>
    <body>
    <asp:label id="whoami" runat="server" />
    </body>
    </html>

    Here's the output:

    As you can see, I have first defined a variable named "name", set things up so that it will hold string data, and assigned a value ("Neo") to it. In my HTML code, I have defined a "label" server control called "whoami". In the
    Page_Load() function, I have used basic string concatenation to incorporate the value of the "name" variable into the "Text" property of the "whoami" label.

    If you alter the value assigned to the "name" variable, the output of the page generated will change to reflect the new name. Try it and see for yourself!

    You can also define a variable without assigning a value to it, or assign a value to it at a later stage - for example, the following code snippets are equivalent.


    string name// define the variable
    name "The One"// and initialize it


    string name="The One"// define and initialize a variable simultaneously

    C# is a strongly typed language - in simple English, this means that each variable can only store a particular type of data. For example, I have defined the variable as a "string" datatype. I cannot store a number in this variable; if I try, as in the example below, I'll see an ugly error
    message:


    // define a variable as string and initialize it to a number
    string num 1

    Define the number as a string, though, and it works out fine:


    // define a variable as string and 
    // initialize it to a number stored as a string value
    string num "1";

    Of course, the drawback of the above solution is that the "name" variable does not store the value "1" as a number and hence cannot be used for operations like addition, subtraction or multiplication.

    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




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