w3pop.com :: ÍøÂçѧԺ :: ASP.NET :: asp.netµÄÍøÒ³
A simple ASP.NET page looks just like an ordinary HTML page.
Ò»¸ö¼òµ¥µÄasp.netµÄÒ³Ãæ¿´ÆðÀ´¾ÍÏñÊÇÒ»¸öÆÕͨµÄhtmlÍøÒ³.
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!
|
This code displays the example as an HTML page:
Õâ¸ö¾ÙÀýµÄHTMLÒ³ËùÓõ½µÄ´úÂë:
<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
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> |
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µÄÁ´½Ó
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Ò³ÃæµÄÇø±ð¡£
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Ò³ÃæÖÐÕý³£ÔË×÷¡£
To demonstrate how ASP can display pages with dynamic content, we have added some executable code (in red) to the previous example:
ÒªÑÝʾÈçºÎ²ÅÄÜÈÃASPÏÔʾ¶¯Ì¬µÄÄÚÈÝ£¬ÎÒÃÇÔÚ´úÂëÀï¼ÓÈëÁËһЩ¿ÉÖ´ÐеĴúÂë(ºìÉ«²¿·Ö)
<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
This following code displays our example as an ASP.NET page:
ÒÔÏ´úÂë¾Í×÷ΪÎÒÃÇASP.NETÒ³µÄÀý×Ó
<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
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