ÍøÂçѧԺ w3popÉçÇø ÍøÂç×ÊÔ´ ITÐÂÎÅ

w3pop.com :: ÍøÂçѧԺ :: ASP.NET :: asp.netµÄÍøÒ³

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

Íü¼ÇÃÜÂë? ×¢²á

ASP.NET
ASP.NET ½éÉÜ
ASP ºÍ ASP.NET Ö..
asp.netµÄ°²×°
asp.netµÄÍøÒ³
ASP.NET - ·þÎñÆ÷..
ASP.NET - ʼþ
ASP.NET Web ±íµ¥
ASP.NET ά³Öä¯ÀÀ..
ASP.NET - TextBo..
ASP.NET - °´Å¥¿Ø..
ASP.NET - Data B..
ASP.NET - The Ar..
ASP.NET - The Ha..
ASP.NET - The So..
ASP.NET - XML ÎÄ..
ASP.NET - Repeat..
ASP.NET - The Da..
ASP.NET - Databa..
ASP.NET 2.0 ÐÂÌØ..
ASP.NET 2.0 - Ma..

asp.netµÄÍøÒ³


×÷Õß:w3schools ·­Òë/ÕûÀí:w3pop.com ·¢²¼:2007-08-01 ä¯ÀÀ:3263 :: ::

A simple ASP.NET page looks just like an ordinary HTML page.
Ò»¸ö¼òµ¥µÄasp.netµÄÒ³Ãæ¿´ÆðÀ´¾ÍÏñÊÇÒ»¸öÆÕͨµÄhtmlÍøÒ³.


Hello W3Schools
ÄãºÃw3schools

To start learning ASP.NET, we will construct a very simple HTML page that will display "Hello W3Schools" in an Internet browser like this:
¿ªÊ¼Ñ§Ï°asp.net,ÆäÖÐÎÒÃǽ«¹¹½¨Ò»¸ö·Ç³£¼òµ¥µÄhtmlÒ³Ãæ½«ÏÔʾ"ÄãºÃw3schools"ÔÚä¯ÀÀÆ÷Ï¿´ÊÇÕâÑùµÄ:

Hello W3Schools!

 

 

 


Hello W3Schools in HTML
ÄãºÃw3schoolsÔÚhtmlÀïµÄ´úÂë

This code displays the example as an HTML page:
Õâ¸ö¾ÙÀýµÄHTMLÒ³ËùÓõ½µÄ´úÂë:

<html>
<body bgcolor="yellow">
<center>
<h2>Hello W3Schools!</h2>
</center>
</body>
</html>

If you want to try it yourself, save the code in a file called "firstpage.htm", and create a link to the file like this: firstpage.htm
Èç¹ûÄãÏë³¢ÊÔ×Ô¼º¶¯ÊÖ,¿É½«´úÂë±£´æÎª"firstpage.htm"²¢½¨Á¢Ò»¸öÎļþÁ¬½Ó£¬ÏñÊÇÕâÑùµÄ:firstpage.htm


Hello W3Schools in ASP.NET
ÄãºÃw3schoolsÔÚasp.net

The simplest way to convert an HTML page into an ASP.NET page is to copy the HTML file to a new file with an .aspx extension.
½«HTMLÒ³Ãæ×ª»»³ÉASP.NET×î¼òµ¥µÄ·½·¨¾ÍÊǽ«HTMLÎļþ¿½±´Ò»·Ýºó½«Æäºó׺Ãû¸Ä³É.aspx.

This code displays our example as an ASP.NET page:
ÕâЩ´úÂë¾Í×÷ΪÎÒÃǾÙÀýÖеÄASP.NETÒ³Ãæ

<html>
<body bgcolor="yellow">
<center>
<h2>Hello W3Schools!</h2>
</center>
</body>
</html>

If you want to try it yourself, save the code in a file called "firstpage.aspx", and create a link to the file like this: firstpage.aspx
ͬÑùµÄ£¬ÄãÏë³¢ÊÔ×Å×Ô¼º¶¯ÊÖ£¬¿ÉÒÔ½«´úÂë·ÅÖõ½ÃûΪ"firstpage.aspx"µÄÎļþÀ²¢ÇÒ´´½¨Ò»¸öÁ¬½Óµ½firstpage.aspxµÄÁ´½Ó


How Does it Work?
Æä¹¤×÷Ô­ÀíÊÇʲô?

Fundamentally an ASP.NET page is just the same as an HTML page.
¸ù±¾ÉϽ²ASP.NET Ò³Ãæ ºÍHTMLÒ³ÃæÒ»Ñù

An HTML page has the extension .htm. If a browser requests an HTML page from the server, the server sends the page to the browser without any modifications.
HTMLÒ³ÃæÓÐÀ©Õ¹Ãû.htm¡£Èç¹ûä¯ÀÀÆ÷Ïò·þÎñÆ÷ÇëÇóä¯ÀÀhtmlÒ³Ãæ,·þÎñÆ÷½«·¢ËÍδ¾­ÈκÎÐ޸ĵÄÒ³Ãæ¸øä¯ÀÀÆ÷.

An ASP.NET page has the extension .aspx. If a browser requests an ASP.NET page, the server processes any executable code in the page, before the result is sent back to the browser.
ASP.ENTÎļþÓÐÀ©Õ¹Ãû.aspx ¡£ Èç¹ûä¯ÀÀÆ÷ÇëÇóÒ»¸öASP.NETÒ³Ãæ£¬ÄÇô·þÎñÆ÷ÏÈÖ´ÐÐËùÓÐÔÚÕâ¸öÒ³ÃæÉÏ¿ÉÖ´ÐеĴúÂ룬´¦ÀíÍê±ÏºóÔÙ½«½á¹û·¢Ë͵½ä¯ÀÀÆ÷ÉÏ¡£

The ASP.NET page above does not contain any executable code, so nothing is executed. In the next examples we will add some executable code to the page to demonstrate the difference between static HTML pages and dynamic ASP pages.
ÉÏÃæ¾ÙÀýÖеÄASP.NETÒ³ÃæÃ»Óаüº¬ÈκοÉÖ´ÐеĴúÂ룬Òò´ËûÓÐʲô¿ÉÖ´Ðеġ£ÔÚÏÂÃæµÄ¾ÙÀýÖÐÎÒÃǽ«¼ÓÈëһЩ¿ÉÖ´ÐеĴúÂ룬À´ÑÝʾһÏÂHTML¾²Ì¬Ò³¸ú¶¯Ì¬µÄASPÒ³ÃæµÄÇø±ð¡£


Classic ASP
¾­µä ASP

Active Server Pages (ASP) has been around for several years. With ASP, executable code can be placed inside HTML pages.
¶¯Ì¬·þÎñÆ÷Ò³Ãæ(asp)ÒѾ­ºÃ¼¸ÄêÁË. ͨ¹ýʹÓÃasp,¿ÉÖ´ÐдúÂë¿É·ÅÖÃÔÚhtmlÍøÒ³Àï.

Previous versions of ASP (before ASP .NET) are often called Classic ASP.
ÔÚASP.NET֮ǰµÄASP°æ±¾¾Í¾­³£³Æ×÷Ϊ¾­µäASP

ASP.NET is not fully compatible with Classic ASP, but most Classic ASP pages will work fine as ASP.NET pages, with only minor changes.
asp.netÊDz»ÍêÈ«·ûºÏ¾­µäaspµÄ,µ«´ó²¿·Ö¾­µäasp´úÂëÖ»ÐèÒª×öÏÂϸСµÄ¸Ä¶¯¾Í¿ÉÔÚASP.NETÒ³ÃæÖÐÕý³£ÔË×÷¡£


Dynamic Page in Classic ASP
ÔÚ¾­µäASPÖеĶ¯Ì¬

To demonstrate how ASP can display pages with dynamic content, we have added some executable code (in red) to the previous example:
ÒªÑÝʾÈçºÎ²ÅÄÜÈÃASPÏÔʾ¶¯Ì¬µÄÄÚÈÝ£¬ÎÒÃÇÔÚ´úÂëÀï¼ÓÈëÁËһЩ¿ÉÖ´ÐеĴúÂë(ºìÉ«²¿·Ö)

<html>
<body bgcolor="yellow">
<center>
<h2>Hello W3Schools!</h2>
<p><%Response.Write(now())%></p>
</center>
</body>
</html>

The code inside the <% --%> tags is executed on the server.
ÔÚ±ê¼Ç<% -- %>ÖеĴúÂë¾ÍÊÇ·þÎñÆ÷Àï¿ÉÖ´ÐеĴúÂë

Response.Write is ASP code for writing something to the HTML output stream.
Response.Write ¾ÍÊÇÄÜÊä³öһЩHTMLÊý¾ÝÁ÷µÄASP´úÂë

Now() is a function returning the servers current date and time.
Now() Ϊһ¸öº¯Êý£¬¿É·µ»Ø·þÎñÆ÷µ±Ç°µÄÈÕÆÚºÍʱ¼ä

If you want to try it yourself, save the code in a file called "dynpage.asp", and create a link to the file like this: dynpage.asp
Èç¹ûÄãÏë×Ô¼º³¢ÊÔһϣ¬¿ÉÒÔ°Ñ´úÂë±£´æÎª"dynpage.asp"¡£È»ºó×ö¸öÁ¬½Óµ½¸ÃÒ³µÄÁ¬½Ó£¬ÏñÕâÑù£ºdynpage.asp


Dynamic Page in ASP .NET
ASP.NET¶¯Ì¬Ò³

This following code displays our example as an ASP.NET page:
ÒÔÏ´úÂë¾Í×÷ΪÎÒÃÇASP.NETÒ³µÄÀý×Ó

<html>
<body bgcolor="yellow">
<center>
<h2>Hello W3Schools!</h2>
<p><%Response.Write(now())%></p>
</center>
</body>
</html>

If you want to try it yourself, save the code in a file called "dynpage.aspx", and create a link to the file like this: dynpage.aspx


ASP.NET vs Classic ASP
ASP.NET Óë ¾­µä ASP

The previous examples didn't demonstrate any differences between ASP.NET and Classic ASP.
ÉÏÃæµÄ¾ÙÀý²¢Ã»ÓбíÏÖ³öasp.netºÍ¾­µäaspÈκβîÒì

As you can see from the two latest examples there are no differences between the two ASP and ASP.NET pages.
ÕýÈçÄã¿ÉÒÔ¿´µ½,×î½üµÄÁ½¸ö¾ÙÀýaspºÍasp.netÒ³ÃæÀïµÄ´úÂëÊÇÒ»ÑùµÄ.

In the next chapters you will see how server controls make ASP.NET more powerful  than Classic ASP.
ÔÚ½ÓÏÂÀ´µÄ¼¸¸öÕ½ÚÖÐ,Ä㽫¿´µ½·þÎñÆ÷¿Ø¼þÊÇÈçºÎÈÃASP.NET±È¾­µäASP¸üΪǿÁ¦µÄ.

ÆÀÂÛ (0) All