当前位置: 首页 > 图文教程 > 网络编程 > ASP > 在VS.NET中编写Web应用程序(三)

ASP
关于网站文件自动备份程序的一点思考
DBTree 1.3.2
抽取10万条数据,想起GetRows()
一份ASP内存的释放的实验报告
[整理版]ASP常用内置函数
Jmail组件发送邮件之绝对能用的函数
虚拟主机重启代码
Access 开发人员常犯错误大全
用Asp如何实现防止网页频繁刷新?
ASP 中使用 HTTP 协议发送参数详解
为什么 Windows2003 的 IIS6.0 不能上传超过 200K 的文件?
ASP类的写法
实例学习如何在ASP中调用DLL
被动式统计网站在线人数
[原创]完美解决ASP 不能更新。数据库或对象为只读。
5天学会asp
Wrance的图片系统目录直读版1.0
信息发布中的判断过期和有效期的东西
小偷程序2
一个ASP中的数组

ASP 中的 在VS.NET中编写Web应用程序(三)


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

      
  
  
  第三部分:开发Web应用程序
  好,现在进行到开发 Web 表单应用程序这一步了。
  
  创建工程文件的框架
  用Visual Studio.NET创建一个Web应用程序并不困难,只需遵循几个简单步骤,向导就会为你创建一个很好的框架。此后,就可以用Web控件制工具箱向ASP页面中安置一些Web控件,然后就象在任何基于GUI应用程序的表单中所做的那样,设置这些控件属性。请跟随以下步骤:
  
  第一步:选择一个工程文件
  从Visual Studio .NET 主菜单中,选择“文件->新建>工程文件”,选择“Visual C# 工程文件->Web应用程序”,在文件名文本框中键入你的工程文件名,在位置文本框中是你的web服务器的根目录,使用浏览按钮可以找到正确的路径。选择了这些内容之后,点击 OK。
  
  第二步:设置属性
  下一个画面是这样的:
  
  WebForm1.aspx是默认的ASP.NET页面,其中容纳了ASP.NET代码和控件。你可以把这个页面当作一个WebForm来对待。使用左侧的工具箱,向页面中拖曳和放置控件。
  在页面上点击右键来设置页面的属性,图示如下:
  
  这个窗口共有3个功能页,通用页让你选择脚本语言和页面版面,另外两个用于设置页面文本、超级链接以及被访问过的超级链接和关键字的颜色和字体。
  第三步:向 WebForm增加控件
  现在使用工具箱向页面中增加Web控件。这里增加了两个控件,一个按钮和一个 DataGrid 。点击右键可以设置这些控件的属性。
  
  第四步:增加事件处理器
  这以前已经展示了 DataGrid 和ADO.NET,下面将使用同样的技术,在DataGrid中填充一个数据库的数据。点击Button来填充栅格。
  双击这个按钮,进入WebForm1.cs文件中,开始编写与按钮相应的事件处理器:
  
  Button1.Click += new System.EventHandler (this.Button1_Click);
  public void Button1_Click (object sender,System.EventArgs e)
  {
  }
  Here is the code of the cs file -
  namespace CSCornerWebAppSample
  {
  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;
  /// <summary>
  /// Summary description for WebForm1.
  /// </summary>
  public class WebForm1 : System.Web.UI.Page
  {
  protected System.Web.UI.WebControls.DataGrid DataGrid1;
  protected system.Web.UI.WebControls.Button Button1;
  public WebForm1()
  {
  Page.Init += new System.EventHandler(Page_Init);
  }
  protected void Page_Load(object sender, EventArgs e)
  {
  if (!IsPostBack)
  {
  //
  // Evals true first time browser hits the page
  //
  }
  }
  protected void Page_Init(object sender, EventArgs e)
  {
  //
  // CODEGEN: This call is required by the ASP+ Windows Form Designer.
  //
  InitializeComponent();
  }
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {
  Button1.Click += new System.EventHandler (this.Button1_Click);
  this.Load += new System.EventHandler (this.Page_Load);
  }
  public void Button1_Click (object sender, System.EventArgs e)
  {
  }
  }
  }