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

ASP
session的用法具体解说
模仿PHP写的ASP分页
用排序串字段实现树状结构(例程:保存贴子内容)
Recordset对象方法详解
为Html 的Select 加一个提示语和输入方法
PerlScript编写ASP
嘿,大家瞧瞧这老外在页面之间传递元素的办法
防止使用者按上一頁按鈕
利用owc建立EXECL的例子
ASPHttp使用范例-远程读取别人的页面,并自动写入库
实现文件下载而不是由ie打开的代码
ASP在Scripting.Dictionary对象的作用是什么?
一种效率极高的分类算法(转--非常好,帮助很大对于想做好asp的朋友)
论坛关键技术,树状记录表的堆栈展开
例子:文本搜索
用ASP实现播放Flash的例子
利用global.asa计划执行程序(转)
关于如何保障Winnt +asp +sql web站点的安全经验
用Asp修改注册表
优化MICROSOFT ACCESS提高速度

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


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