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

ASP
asp搜索两个以上的词的原理
如何使用花生壳?
asp汉字转换成汉语拼音代码
asp程序实现伪静态的代码
asp处理xml数据的发送、接收类
ASP中使用jmail发送邮件的函数
asp中获取字符串中的时间字符串
ASP按照字数限制自动截取标题内容
asp中将内容生成word文档的函数
用ASP自动清空IE缓存里的内容
asp检测conn.execute是否执行成功的函数
自动获取当前页面URL的ASP函数
ASP采集中获取网页内所需的html代码
asp图片采集并且本地重命名保存的函数
如何使用asp去字符串中的超链接
asp网站通过限制请求防止被采集的函数
asp利用正则去掉字符串中所有html内容
用ASP取出HTML里面的图片地址的函数
fso实现整个文件夹内容的复制到另一个文件夹中
适合所有表的添加、删除、修改的函数

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


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