使用C# Builder建一个简单的ASP.NET应用程序

王朝c#·作者佚名  2006-01-08
宽屏版  字体: |||超大  

悠游在线(yousoft.hi.com.cn) 作者:徐长友

一般网站建设通常要求开发人员做后台的程序设计,前面有专业的美工做界面设计。虽然有时候开发人员也会做些界面设计,但是通常都无法达到专业的要求。在以前的ASP中,由于代码和HTML页面语言混杂在一起,这就使得网站的建设变得相当的困难。但在ASP.NET中,这种情况完全改变了。 下面就用C# Builder建一个简单的ASP.NET应用程序。

打开C# Builder,选择 File>New>other…菜单项,你将会看到下面的窗口:

screen.width-430)this.width=screen.width-430" align=center border=0

我们选择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),如图:

screen.width-430)this.width=screen.width-430" align=center border=0

按F9运行程序,你就会看到你的一个简单的ASP.NET Web页面。是不是很简单?

screen.width-430)this.width=screen.width-430" align=center border=0

以下是我们建的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页面,这样就大大简化了网站的建设过程。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有