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

ASP
对连串英文自动换行的解决方法 IE5.5
怎样写你自己的EMAIL组件(原理)
ASP中有关timeout超时的体会
用ASP实现从SQL Server导出数据到Access
ASP向NT域中加一个用户
ASP乱码的解决方法
关于 aspsmartupload 注册问题
利用XML不离开页面刷新数据
IIS 处理 SEARCH 请求漏洞
不用组件实现上载功能(1)
不用组件实现上载功能(2)
在网页中实现OICQ里的头像选择的下拉框
仅用xsl和asp实现分页功能
如何使用context()方法将数据置入表格(XML)
利用ASP从远程服务器上接收XML数据
将数据库里面的内容生成EXCEL
怎样在ASP里面创建统计图表
加密你的Access数据库
利用global.asp定时执行ASP
加密QueryString数据

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 160 ::
收藏到网摘: 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)
  {
  }
  }
  }