基于(System.Web.UI.Page)PageBase常用操作

 public class PageBase:System.Web.UI.Page
    {  
        /// <summary>
        /// 重写页面第一次加载事件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPreInit(EventArgs e)
        {
            CheckValid();
            base.OnPreInit(e);
        }
        /// <summary>
        /// 重写页面呈现方法
        /// </summary>
        /// <param name="writer"></param>
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            TitleBase();
            base.Render(writer);
        }
        /// <summary>
        /// 表单验证
        /// </summary>
        public void FormValid<M>(AbstractValidator<M> v) where M:new ()
        {
            var model = new M();
            var results = v.Validate(model);
            ValidMsg msg = new ValidMsg();
            msg.IsValid = results.IsValid;
            if (!results.IsValid)
            {
                foreach (var failure in results.Errors)
                {
                    msg.ErrMessage = failure.PropertyName + " : " + failure.ErrorMessage;
                }
            }
            if (!msg.IsValid) {
                Response.Write(msg.ErrMessage);
            }
           
        }
        /// <summary>
        /// 身份验证
        /// </summary>
        public void CheckValid() { 
        
        }
        /// <summary>
        /// 标题
        /// </summary>
        public void TitleBase() { 
        
        }

    }

 

posted @ 2014-04-13 23:19  wiphom.bear  阅读(433)  评论(0编辑  收藏  举报