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() { } }