您现在的位置: 军旅同心-旅游自驾-军旅文学 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 正文
asp.net高级教程(五)-实战篇(中)
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 12:37:04
lt;td bgcolor='#0097c0' width='1'>
       <img src='images/Shim.gif' width=1>
      </td>
   <!-------------------右边竖线---------------------------------------------->
    </tr>
    
    <!-------------------下边横线---------------------------------------------->
    <tr>
     <td colspan=3 height=1 bgcolor=#0097c0><img src='images/shim.gif'width=1 height=1></td>    
    </tr>
    <!-------------------下边横线---------------------------------------------->
</table>

    <My:bottom id="myBottom" runat="server"></My:bottom>
    </form>
  </BODY></HTML>

<!--------------------文件结束--------------------------------->

    怎么样,看上去很熟悉吧,除了页首两句及下面webform中带runat=server的webcontrol,是不是和普通的html一样?注意到页首第一句中的Codebehind="Register.cs"吗,它指定本页后面的代码文件是register.cs,这是asp.net提供的一种机制,它可以将业务逻辑隐藏在与.aspx同名的cs文件中,而运行时先把这个cs文件编译,这样不但可以提高运行效率,也使代码隐藏起来,避免了asp中由于系统漏洞而造成源码泄漏所造成的问题。那么,这个包含业务逻辑的代码文件是怎样的呢?下面是这个文件:
namespace bbs
{
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data.SQL;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using bbs.uctrl ;
    //using bbs.MyClass ;
    using MyOwnClass ;

    /// <summary>
    ///    Summary description for Register.
    /// </summary>
    public class Register : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.Button btnSubmit;
        protected System.Web.UI.WebControls.TextBox txtHomepage;
        protected System.Web.UI.WebControls.TextBox txtEmail;
        protected System.Web.UI.WebControls.CompareValidator comPassword;
        protected System.Web.UI.WebControls.TextBox txtPassword1;
        protected System.Web.UI.WebControls.RegularExpressionValidator Regularexpressionvalidator1;
        protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator1;
        protected System.Web.UI.WebControls.TextBox txtPassword;
        protected System.Web.UI.WebControls.CustomValidator cusUserName;
        protected System.Web.UI.WebControls.RegularExpressionValidator regUserName;
        protected System.Web.UI.WebControls.RequiredFieldValidator reqUserName;
        protected System.Web.UI.WebControls.Label lblMessage;
        protected System.Web.UI.WebControls.TextBox txtUserName;
        public MyHead myHead1 ;

        //构造函数
        public Register()
        {
            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();
            this.myHead1.Position = 2 ;
        }

        /// <summary>
        ///    Required method for Designer support - do not modify
        ///    the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.Load += new System.EventHandler (this.Page_Load);
        }

        //监测用户是否存在
        public bool ValidUser(Object sender , string value)
        {
            BBSUser myUser = new BBSUser() ;
            bool bExists ;
            try
            {
                bExists = myUser.GetUser(this.txtUserName.Text) ;            
            }
            catch(Exception e)        //如果出现异常
            {
#if DEBUG
                Response.Write (e.Message) ;
                return false ;
#endif
                Server.Transfer("error.aspx") ;
                
            }    
                
            return !bExists ;            
        }

        //提交按钮点击
        public void OnSubmit(Object sender , EventArgs e)
        {
            if (Page.IsValid)
            {
                //数据入库
                try
                {
                    BBSUser myUser = new BBSUser() ;
                    if(!myUser.GetUser(txtUserName.Text))
                    {
                        myUser.CreateUser(BBSUser.CreateType.Create , txtUserName.Text , txtPassword.Text ,
      &nb

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


更多
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 网站地图 | 版权申明 | 网站公告 | 管理登录 |