学习cnblogsGuestBook V2.0
下载了cnblogsGuestBook V2.0 的源码,在Vs.net里调试了一下,并照着它的思路自己重做了一个。
对“窗体设计器”有了一个新的认识,可见偶的菜鸟看点http://www.cnblogs.com/lovewangshu/archive/2005/03/22/123305.html
通过“窗体设计器”往页面上拖Connection、DataAdapter、DataSet对象,在页面类中自动添加对应的类属性,如:
public class _default : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtboxTitle;
protected System.Web.UI.WebControls.TextBox txtboxContent;
protected System.Web.UI.HtmlControls.HtmlTableCell TD1;
protected System.Data.OleDb.OleDbDataAdapter da;
protected System.Data.OleDb.OleDbConnection conn;
protected System.Web.UI.WebControls.DataList dlList;
protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
protected cnblogsGuestbook.ds ds1;
protected System.Web.UI.WebControls.Button btnSubmit;
根据自己的配置,“窗体设计器”自动生成初始化的方法,如:
private void InitializeComponent()
{
this.da = new System.Data.OleDb.OleDbDataAdapter();
this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
this.conn = new System.Data.OleDb.OleDbConnection();
this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
this.ds1 = new cnblogsGuestbook.ds();
((System.ComponentModel.ISupportInitialize)(this.ds1)).BeginInit();
this.dlList.ItemCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.dlList_ItemCommand);
this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
//
// da
//
this.da.DeleteCommand = this.oleDbDeleteCommand1;
this.da.InsertCommand = this.oleDbInsertCommand1;
this.da.SelectCommand = this.oleDbSelectCommand1;
this.da.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "tbl_msg", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("msg_content", "msg_content"),
new System.Data.Common.DataColumnMapping("msg_id", "msg_id"),
new System.Data.Common.DataColumnMapping("msg_time", "msg_time"),
new System.Data.Common.DataColumnMapping("msg_title", "msg_title")})});
this.da.UpdateCommand = this.oleDbUpdateCommand1;
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
..
}
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
对“窗体设计器”有了一个新的认识,可见偶的菜鸟看点http://www.cnblogs.com/lovewangshu/archive/2005/03/22/123305.html
通过“窗体设计器”往页面上拖Connection、DataAdapter、DataSet对象,在页面类中自动添加对应的类属性,如:
![](https://www2.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
根据自己的配置,“窗体设计器”自动生成初始化的方法,如:
![](https://www2.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/dot.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/None.gif)
这个方法在override protected void OnInit(EventArgs e)中被调用,
![](https://www2.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www2.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
页面第一次被打开时,执行顺序为:OnInit()-------InitializeComponent()-------base.OnInit(e)------Page_Load()
可以理解为页面类的构造过程中已经完成了页面类属性的初始化,页面类的其他方法,可以直接使用这些属性。这样,可以避免V1.0 中出现的其他方法重复配置Ado.net组件的毛病。
偶对V2.0 的认识在于:V2.0 充分利用了“页面”相当于“类”,以及“类”的一些操作特点,来实现留言本。