打印本文 打印本文 关闭窗口 关闭窗口
ASP.NET的模板实现(c#)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数1920  更新时间:2009/4/23 10:50:44  文章录入:mintao  责任编辑:mintao
              writer.Write(@"</td></tr><tr><td width=''''100%'''' colspan=''''3''''>页脚 </td></tr></table></body></html>");

             

         }

   }

上面的PageBase.cs就是我们的自定类,这样,我们在其他ASPX页面中就可以直接继承PageBase这个类,而非System.Web.UI.Page,下面分别是index.aspx和newContact.aspx的代码(分别包含index.aspx.cs和newContact.aspx.cs):

Index.aspx

<%@ Page language="c#" Codebehind="index.aspx.cs" AutoEventWireup="false" Inherits="wab.index" %>

<form id="index" method="post" runat="server">

       <asp:DataGrid id="contacts" runat="server" Width="492px" Height="104px"></asp:DataGrid>

</form>

index.aspx.cs(继承自定义类PageBase)

       public class index : PageBase

       {

              protected System.Web.UI.WebControls.DataGrid contacts;

      

              private void Page_Load(object sender, System.EventArgs e)

              {

                     // 在此处放置用户代码以初始化页面

              }

              #region Web Form Designer generated code

              override protected void OnInit(EventArgs e)

              {

                     //

                     // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。

                     //

                     InitializeComponent();

                     base.OnInit(e);

              }

             

              /// <summary>

              /// 设计器支持所需的方法 - 不要使用代码编辑器修改

              /// 此方法的内容。

              /// </summary>

              private void InitializeComponent()

              {   

                     this.Load += new System.EventHandler(this.Page_Load);

 

              }

              #endregion

       }

newContact.aspx

<%@ Page language="c#" Codebehind="newContact.aspx.cs" AutoEventWireup="false" Inherits="wab.newContact" %>

<form id="newContact" method="post" runat="server">

       <P><FONT face="宋体">名子</FONT>

              <asp:TextBox id="TextBox1" runat="server"></asp:TextBox></P>

       <P><FONT face="宋体">姓氏</FONT>

              <asp:TextBox id="TextBox2" runat="server"></asp:TextBox></P>

       <P>

              <asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P>

</form>

newContact.aspx.cs(继承自定类PageBase)

       public class newContact : PageBase

       {

              protected System.Web.UI.WebControls.TextBox TextBox1;

              protected System.Web.UI.WebControls.Button Button1;

              protected System.Web.UI.WebControls.TextBox TextBox2;

      

              private void Page_Load(object sender, System.EventArgs e)

              {

              }

 

              #region Web Form Designer generated code

              override protected void OnInit(EventArgs e)

              {

                     //

                     // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。

上一页  [1] [2] [3]  下一页

打印本文 打印本文 关闭窗口 关闭窗口