当前位置: 首页 > 网络学院 > 服务端脚本教程 > ASP.NET > asp.net的网页

ASP.NET
ASP.NET 2.0 - Navigation 导航
C#中new和override区别
ASP.NET中 Bin,App_Browser,App_code,App_Data,App_Theme 等文件

ASP.NET 中的 asp.net的网页


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 1063 ::
收藏到网摘: n/a

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是不完全符合经典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

登陆 | 还没注册?