【源码】c# pagebase 用法提升
2011-11-28 17:00
246 查看
pagebase 用法提升
以往在一些需要登录的页面,总会去在每个页面去分别判断用户是否登录或者在WEBCONFIG里面设定一些登录方式,如果没有登录就马上回滚跳转之类的方法今天看到一个更加有趣的方法,也更加实用和灵活,就是创建一个PAGEBASE 的基类继承原始的PAGE类,然后以后的页面都继承这个PAGEBASE类,具体的验证方法都在PAGEBASE里面完成,即使以后子页面有自己独体的验证方法,也可以去重写PASEBASE类里面的验证方法,很灵活,很给力 using System;using System.Web.UI;namespace RonghangOAServer{ /// <summary> /// 页面层(表示层)基类,所有页面继承该页面 /// </summary> public class PageBase : System.Web.UI.Page { /// <summary> /// 构造函数 /// </summary> public PageBase() { //this.Load+=new EventHandler(PageBase_Load); } protected override void OnInit(EventArgs e) { base.OnInit(e); // this.Load += new System.EventHandler(PageBase_Load); //向页面注册onload方法 this.Error += new System.EventHandler(PageBase_Error); //向页面注册onerror方法 } //错误处理 protected void PageBase_Error(object sender, System.EventArgs e) { Server.Transfer("default.aspx"); } protected virtual void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { Response.Write("这个是基类的页面初始化方法"); } } }} using System;using System.Web;using System.Web.UI;using RonghangOAServer;public partial class Default2 : PageBase{ //protected void Page_Load(object sender, EventArgs e) //{ // 这里会调用基类的ONLOAD方法 //} protected override void Page_Load(object sender, EventArgs e) { Response.Write("这里覆盖了页面初始化方法"); //子页面重写ONLOAD方法 string s = "3"; Response.Write(s[7]); }}
以往在一些需要登录的页面,总会去在每个页面去分别判断用户是否登录 或者在WEBCONFIG里面设定一些登录方式,如果没有登录就马上回滚跳转之类的方法 今天看到一个更加有趣的方法,也更加实用和灵活,就是创建一个PAGEBASE 的基类继承原始的PAGE类,然后以后的页面都继承这个PAGEBASE类,具体的验证方法都在PAGEBASE里面完成,即使以后子页面有自己独体的验证方法,也可以去重写PASEBASE类里面的验证方法,很灵活,很给力 using System; using System.Web.UI; namespace RonghangOAServer { ///<summary> /// 页面层(表示层)基类,所有页面继承该页面 ///</summary> public class PageBase : System.Web.UI.Page { ///<summary> /// 构造函数 ///</summary> public PageBase() { //this.Load+=new EventHandler(PageBase_Load); } protected override void OnInit(EventArgs e) { base.OnInit(e); // this.Load += new System.EventHandler(PageBase_Load); //向页面注册onload方法 this.Error += new System.EventHandler(PageBase_Error); //向页面注册onerror方法 } //错误处理 protected void PageBase_Error(object sender, System.EventArgs e) { Server.Transfer("default.aspx"); } protected virtual void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { Response.Write("这个是基类的页面初始化方法"); } } } } using System; using System.Web; using System.Web.UI; using RonghangOAServer; public partial class Default2 : PageBase { //protected void Page_Load(object sender, EventArgs e) //{ // 这里会调用基类的ONLOAD方法 //} protected override void Page_Load(object sender, EventArgs e) { Response.Write("这里覆盖了页面初始化方法"); //子页面重写ONLOAD方法 string s = "3"; Response.Write(s[7]); } }
以往在一些需要登录的页面,总会去在每个页面去分别判断用户是否登录或者在WEBCONFIG里面设定一些登录方式,如果没有登录就马上回滚跳转之类的方法今天看到一个更加有趣的方法,也更加实用和灵活,就是创建一个PAGEBASE 的基类继承原始的PAGE类,然后以后的页面都继承这个PAGEBASE类,具体的验证方法都在PAGEBASE里面完成,即使以后子页面有自己独体的验证方法,也可以去重写PASEBASE类里面的验证方法,很灵活,很给力 using System;using System.Web.UI;namespace RonghangOAServer{ /// <summary> /// 页面层(表示层)基类,所有页面继承该页面 /// </summary> public class PageBase : System.Web.UI.Page { /// <summary> /// 构造函数 /// </summary> public PageBase() { //this.Load+=new EventHandler(PageBase_Load); } protected override void OnInit(EventArgs e) { base.OnInit(e); // this.Load += new System.EventHandler(PageBase_Load); //向页面注册onload方法 this.Error += new System.EventHandler(PageBase_Error); //向页面注册onerror方法 } //错误处理 protected void PageBase_Error(object sender, System.EventArgs e) { Server.Transfer("default.aspx"); } protected virtual void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { Response.Write("这个是基类的页面初始化方法"); } } }} using System;using System.Web;using System.Web.UI;using RonghangOAServer;public partial class Default2 : PageBase{ //protected void Page_Load(object sender, EventArgs e) //{ // 这里会调用基类的ONLOAD方法 //} protected override void Page_Load(object sender, EventArgs e) { Response.Write("这里覆盖了页面初始化方法"); //子页面重写ONLOAD方法 string s = "3"; Response.Write(s[7]); }}
相关文章推荐
- C#中base关键字的几种用法
- C#中base关键字的几种用法
- c# base关键字的用法
- C#中base关键字的几种用法
- 【转】C#中base关键字的几种用法
- C#:base与this关键字用法小结
- C#中base两种用法
- C#中base关键字的几种用法
- PageBase 基本用法
- 转:C#中base关键字的几种用法
- C#中this的用法,你用过几种?【含源码示例】
- C#里面base的有趣用法1
- c# winform 中的 工具栏自动隐藏 splitter用法 带源码
- 转:C#中base关键字的几种用法
- C# 中 this 和 base 的用法
- C#中this的用法,你用过几种?【含源码示例】
- c# 的继承,继承类实例化的时候,会先调用基类的构造函数,然后再调用自己的构造函数,base 的用法,有override和没有override的区别
- C#中base的用法
- C#中的CollectionBase用法
- C#中this的用法,你用过几种?【含源码示例】