First, start
1 Introduction
Welcome to ASP.NET immediately to tutorial.
ASP.NET immediately tutorial is made up of a series of instances and support, and his purpose is to let developers quickly understand the Spectacular, framework of the ASP.NET, the power of the ASP.NET network application framework. All instance designs are short and easy to understand, and the corresponding functions of ASP.NET can be fully demonstrated. After learning the tutorial, you should be familiar with the following:
· ASP.NET syntax. Of course, for skilled ASP developers, some ASP.NET syntax elements are familiar, but some are unique to the new framework. The instance of this tutorial covers details of all syntax elements.
· ASP.NET structure and characteristics. This tutorial introduces the characteristics of ASP.NET, which allows developers to establish interactive, world-class applications with before an unprecedented efficiency.
·Best Practices. An example of this tutorial demonstrates the best way for ASP.NET features, and there is also a potential defect.
The level of readers of this textbook:
If you have never had experience in developing a web page, then this textbook is not suitable for you. You should be familiar with HTML and general web development terms. You don't have to have an experience of ASP, but you should be familiar with the concept of interactive pages, including forms, scripts, and data access.
Example of digestion and absorption of this textbook
This textbook is the best practice of the presentation. Each instance is built on the concept of the concept and the quotation of the previous instance. This example is a complete series from simple to complex, from single technology to applications.
2, what is ASP.NET
ASP.NET is an application framework based on the General Language Runtime Library (CLR). He is used to build a powerful web application on the server side. ASP.NET provides several advantages that transcend the previous web development model:
· Enhanced performance. ASP.NET is the compiled CLR code running on the server, not explained like ASP. ASP.NET uses advance binding, instant compile, local optimization, and cache services to improve performance. All of this, performance is far greater than every line of code you wrote in the past.
· World-class development tool support. In the Integrated Development Environment (IDE) of the Visual Studio .NET, the ASP.NET framework consists of rich toolboxes and designers. WySIWYG) editing method, drag and drop server control, and automatic deployment, just a small number of features provided by this powerful tool.
· Powerful and elastic. Since ASP.NET is based on (CLR), the powerful and elasticity of the entire .NET platform can also be applied to web application developers. The .NET framework library, message, and data access solutions can be seamlessly integrated into the web. ASP.NET is also language neutral, so you can choose the language you are most familiar, or through several languages to complete an app. Moreover, the interoperability of the CLR guarantees that when you upgrade to Asp.nt, existing CoM-based development investment is still reserved.
·simple. ASP.NET makes it easy to perform a commonly used job, such as submission from simple forms, client authentication, deployment and site configuration. For example, ASP.NET allows you to establish a user interface, implement the separation of the page and logic code, while processing events like VB's form execution mode (that is, the page drive mode is turned into an event drive mode). In addition, the CLR simplifies deployment to manage code services, such as automatic reference and garbage collection.
· Easy to manage. ASP.NET uses a text-based, hierarchical configuration system, which simplifies the server-side environment and web applications. Since the configuration information is saved in plain text format, new settings do not require support for local management tools. This "zero local support" concept is also applied to deploying an ASP.NET application. ASP.NET applications are deployed to the server, simplifying to copy the necessary files to the server. When deploying, even replacing the running variant code, you don't need to restart the server. · Scalability and effective utilization. ASP.NET is designed to improve performance for cluster and multiprocessor environment. Moreover, the ASP.NET runs closely monitors and manages the process, so that if an error occurs, such as vulnerabilities and deadlocks, new processes are established in the current location to help your application continue to process event requests.
· Can be customized and expanded. ASP.NET provides a good expansion structure that allows developers to "insert" their code in the appropriate level. In fact, using your own written components can expand or replace any subcomponents at the ASP.NET runtime. Performing a custom verification or status service becomes unprecedented.
·safety. Built-in Windows verification and independent configuration of each application, you can think that your application is safe.
The next ASP.NET tutorial will show you the practice of these concepts.
3, language support (C # version)
language support
Microsoft's .NET platform now provides built-in three language support: C #, Visual Basic, and JScript. The practice and instance code of this textbook show how to use these three languages .NET applications. For more syntax information about other languages, please refer to the .NET Framework SDK document.
The code segment provided below helps you understand the code instance in this textbook, and the differences between these three languages.
Variable declaration
INT X;
String S;
String S1, S2;
Object O;
Object obj = new object ();
Public String Name;
Statement
Response.write ("foo");
Comment
// This is a single line of comments
/ *
this is
many
Row
Note * /
Access to index properties
String s = request.QueryString ["name"];
String value = Request.cookies ["key"];
Disclaimer index properties
// Default Indexed Property
Public String this [string name] {
Get {
Return (String) lookuptable [name];
}
}
Disclaimer simple properties
PUBLIC STRING NAME {
Get {
...
Return ...
}
SET {
... = Value;
}
}
Declaration and use enumeration
// Declare the enumeration
Public Enum messageSize {
Small = 0,
MEDIUM = 1,
Large = 2
}
// Create a Field or Property
Public Messagesize Msgsize;
// Assign to the property using the enumeration value
Msgsize = small;
Traversal collection
FOREACH (String S in Coll) {
...
}
Declaration and use
// Declare a void return function
Void voidfunction () {
...
}
// Declare a Function That Returns a Value
String stringfunction () {...
Return (String) Val;
}
// Declare a Function That Takes and Returns Values
String ParmFunction (String a, string b) {
...
Return (String) (A B);
}
// use the functions
VoidFunction ();
String s1 = stringfunction ();
String S2 = PARMFunction ("Hello", "World!");
Custom attribute
// Stand-Alone Attribute
[Stathread]
// attribute with parameters
[DLLIMPORT ("Advapi32.dll")]]]]]
// attribute with named parameters
[DLLIMPORT ("kernel32.dll", charset = charSet.Auto)]
Array
String [] a = new string [3];
a [0] = "1";
a [1] = "2";
a [2] = "3";
String [] [] a = new string [3] [3];
a [0] [0] = "1";
A [1] [0] = "2";
a [2] [0] = "3";
initialization
String s = "Hello World";
INT i = 1;
Double [] a = {3.00, 4.00, 5.00};
IF statement
IF (Request.QueryString! = null) {
...
}
CASE statement
Switch (firstname) {
Case "john":
...
Break;
Case "Paul":
...
Break;
Case "rinco":
...
Break;
DEFAULT:
...
Break;
}
FOR cycle
For (int i = 0; i <3; i )
A (i) = "test";
While cycle
INT i = 0;
While (i <3) {
Console.writeline (i.tostring ());
i = 1;
}
Abnormal processing
Try {
// Code That Throws Exceptions
} catch (overflowexception e) {
// catch a specific Exception
} catch (exception e) {
// catch the generic exceptions
} finally {
// Execute Some Cleanup Code
}
String connection
// using strings
String S1;
String S2 = "Hello";
S2 = "world";
S1 = S2 "!!!";
// Using StringBuilder Class for Performance
StringBuilder S3 = New StringBuilder ();
S3.Append ("Hello");
S3.Append ("world"); s3.append ("!!!");
Event processing delegation
Void MyButton_Click (Object Sender,
Eventargs e) {
...
}
Declaration event
// Create a public evenet
Public Event athandler myevent;
// Create a Method for Firing the Event
Protected void OnmyEvent (Eventargs E) {
MyEvent (this, e);
}
Add or remove event processing to events
Control.change = New EventHandler (this.changeeeventhandler);
Control.change - = New EventHandler (this.changeeeventhandler);
structure
MyObject obj = (myObject) session ["Some Value"];
IMyObject IOBJ = OBJ;
Conversion
INT i = 3;
String s = i.to.tostring ();
Double d = double.parse (s);
Class definition with inheritance
Using system;
Namespace myspace {
PUBLIC CLASS foo: bar {
INT X;
Public foo () {x = 4;
Public void add (int x) {this.x = x;}
Override public int GetNum () {returnix}
}
}
// csc /out :lud 帖子 d d:: library
// Library.cs
Implement interface
Public class myclass: ienumerable {
...
IEnumerator ienumerable.getenumerator () {
...
}
}
Class definition with main method
Using system;
Public class consolecs {
Public consolecs () {
Console.writeline ("Object Created");
}
Public static void main (String [] args) {
Console.writeline ("Hello World");
Consolecs ccs = new consolecs ();
}
}
// csc /out:consolecs.exe / T: EXE Console.cs
Standard template
Using system;
Public class module {
Public static void main (String [] args) {
Console.writeline ("Hello World");
}
}
// csc /out:consolecs.exe / T: EXE Console.cs
After the above introduction, we will start talking about ASP.NET Web Forms .......