C# Builder建一个ASP.NET应用程序
添加时间: 2007-7-13 2:01:59 作者: C#教程 阅读次数:26 来源: http://www.d9soft.com
一般网站建设通常要求开发人员做后台的程序设计,前面有专业的美工做界面设计。虽然有时候开发人员也会做些界面设计,但是通常都无法达到专业的要求。在以前的ASP中,由于代码和HTML页面语言混杂在一起,这就使得网站的建设变得相当的困难。但在ASP.NET中,这种情况完全改变了。下面就用C# Builder建一个简单的ASP.net应用程序。
打开C# Builder,选择 File>New>other…菜单项,你将会看到下面的窗口:
我们选择C# ASP Projects,你就会看到右边有3种可供选择。我们选择ASP.NET Web Application,就可以开始创建我们第一个ASP.NET应用程序。C# Builder会自动在Web程序所在地wwwroot目录下面创建一个虚拟目录,在这里叫做WebApplication1,你可以根据程序的功能取一个其它的什么名字。这时打开IIS,你就会发现产生了一个名为WebApplication1的虚拟目录,如果没有自动创建的话,自己用IIS创建一个虚拟目录。
你会看到C# Builder自动帮你建立了一个名为WebForm1的Web page。这里放上一个label和一个按钮。(注:是HTML Label和HTML Button),如图:
按F9运行程序,你就会看到你的一个简单的ASP.NET Web页面。是不是很简单?
以下是我们建的HTML页面
| <%@ Page language="c#" Debug="true" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="myaspx.WebForm1" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title></title> <meta name="GENERATOR" content="Borland ASP.NET Designer for c# Package Library 7.1"> </head> <body ms_positioning="GridLayout"> <form runat="server"> <input style="Z-INDEX: 2; LEFT: 246px; WIDTH: 75px; POSITION: absolute; TOP: 150px; HEIGHT: 24px" type=button size=25 value=OK><span title style="Z-INDEX: 1; LEFT: 86px; WIDTH: 187px; POSITION: absolute; TOP: 86px; HEIGHT: 27px">我的ASP.NET程序!</span><font color=#ccffcc></font> </form> </body> </html> |
从第一行中我们可以看出,该页面的后台代码全都在WebForm1.aspx.cs文件中。我们可以在这个文件中编写程序,生成的代码如下:
| using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace myaspx { /// <summary> /// Summary description for WebForm1. /// </summary> public class WebForm1 : System.Web.UI.Page { private void Page_Load(object sender, System.EventArgs e) { } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } } } |
通过代码后置,开发人员可以直接修改.cs文件。而页面设计人员可以修改HTML页面,这样就大大简化了网站的建设过程。
上一篇文章: 用C# Builder生成PDF文件 下一篇文章: 设计带图标和自定义颜色的ListBox
相关文章:

