在这里,无涯教程使用在上一个主题中创建的项目。要在现有项目中添加新的Web表单,请首先选择项目,然后右键单击并添加新项。

选择左角的Web表单选项,然后选择Web表单并单击添加按钮。

现在单击Add按钮,此表单将添加到项目中。
添加表单后,可以看到这现在位于项目中,如下图所示。

双击此表单,将显示一些自动生成的代码,如下所示:

//user-form.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="user-form.aspx.cs" Inherits="asp.netexample.user_form" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> </div> </form> </body> </html>
如果在浏览器上运行此文件,它不会显示任何输出。那么,通过这个表单打印一些消息。
修改后的代码如下。
//user-form.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="user-form.aspx.cs" Inherits="asp.netexample.user_form" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <h2>Welcome to the Web Forms!</h2> </div> </form> </body> </html>
在浏览器上运行后,它会产生以下输出。

除了这条消息,还可以做很多事情,还可以向此页面添加控件。无涯教程将在下一章中向窗体添加控件。