First, start
1 Introduction
Welcome to ASP.NET immediately to tutorial.
ASP.NET immediately puts the tutorial is made up of a series of instances and support, his purpose is to let developers quickly
Solve the syntax, framework, and powerful features of the ASP.NET web application framework. All instance design short
Small and easy to understand, fully display the corresponding functions of ASP.NET. After learning the tutorial, you should be familiar with the following
content:
· ASP.NET syntax. Of course, for skilled ASP developers, some ASP.NET syntax elements will be familiar, and some
It is 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 be unprecedented
Establish interactive, world-class applications.
·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 a general
Web development terminology. 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. Should
Examples are 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 on server side
Powerful web applications. 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 as explained like ASP.
. ASP.NET uses advance binding, instant compile, local optimization, and cache services to improve performance. All all this, performance
It is far greater than every line of code you wrote in the past.
· World-class development tool support. ASP.N in the Integrated Development Environment (IDE) of Visual Studio .NET
The ET frame consists of rich toolbox and designer. WySIWYG) editing method, drag and drop server control
Parts, as well as automatic deployment, only 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,
It can also be applied to web application developers. The class library, message, and data access solutions of the .NET framework can
Integrate to the web in seamless. ASP.NET is also language neutral, so you can choose your most familiar language, or pass
Several languages to complete an application. Moreover, the interoperability of the CLR can guarantee that when you upgrade to asp.ent, now
COM-based development investment remains.
·simple. ASP.NET makes it easy to perform commonly used work, such as submission from simple forms, client verification, to
Deployment and site configuration. For example, ASP.NET allows you to create user interfaces, implement the separation of pages and logic code, while
Just like the form of VB's form execution mode (that is, the page drive mode is turned into an event drive mode.
formula). 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 application settings. Since the configuration information is saved in plain text format, new settings do not require support for local management tools.
hold. 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. In deployment, even replacing the running variation code
When you don't need to restart the server.
· Scalability and effective utilization. ASP.NET is designed to be scalable, can be improved for clusters and multiprocessor environment
performance. Moreover, the ASP.NET runs closely monitors and manages the process, so that if an error occurs, for example
Vulnerabilities and dead locks, 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" he at the appropriate level.
Our code. In fact, using your own written components can expand or replace any subgroups at the ASP.NET runtime
Part. 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 app 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. Present textbook
Exercise and instance code show how to build .NET applications using these three languages. More profiles about other languages
For information, please refer to the .NET Framework SDK documentation.
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;
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 this takes and return valuetring 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
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 .......