System.Web.UI.Page的用法,一定要学会懒
2014-12-19 09:27
288 查看
在ASP.NET中,任何页面都是继承于System.Web.UI.Page,他提供了ASP.NET中的Response,Request,Session,Application的操作.在使用Visual Studio 创建ASP页面时,系统会自动为你创建一个继承与System.Web.UI.Page的类与页面文件关联.
我们可以设计一个类,如:
另外,在Page中还有一个重要的方法:
public partial class yourPage:System.Web.UI.Page { protected void Page_Load(Object sender,EventArgs e) { } }
我们可以设计一个类,如:
class myPage:System.Web.UI.Page { } //这种情况下我们可以将页面生成的代码改为 public partial class yourPage:myPage(){ //............. } //这样,我们就可以在myPage中放入一些常用的方法,将代码更有效的复用,同时实现一些错误页面的跳转功能.
另外,在Page中还有一个重要的方法:
protected override void OnInit(EventArgs e) { base.OnInit(e); }
这是页面的初始化时执行的方法,但需要特别注意的是,重写该方法的时候一定要将
base
.OnInit(e)写入,不能留空.
相关文章推荐
- 解读System.Web.UI.Page中关键方法ProcessRequestMain()
- 重写System.Web.UI.Page中OnLoad事件实现Session验证
- 错误:非静态的字段、方法或属性“System.Web.UI.Page.Session.get”要求对象引用
- CS0120: 非静态的字段、方法或属性“System.Web.UI.Page.Request.get”要求对象引用的解决办法
- System.Web.UI.Page
- 解读System.Web.UI.Page中关键方法ProcessRequestMain()
- 继承System.Web.UI.Page的页面基类 示例(转截)
- 非静态的字段、方法或属性“System.Web.UI.Page.Session.get”要求对象引用
- 分析器错误消息: “index.admin.index”不扩展类“System.Web.UI.Page”,因此此处不允许。
- cs文件中不能继承System.Web.UI.Page问题的解决方法
- 这个问题不简单:非静态的字段、方法或属性“System.Web.UI.Page.Request.get”要求对象引用
- 错误:非静态的字段、方法或属性“System.Web.UI.Page.Session.get”要求对象引用
- 继承System.Web.UI.Page的页面基类
- 在Web项目开发中使用BasePage类的巧用(继承System.Web.UI.Page)
- 继承System.Web.UI.Page的页面基类
- 继承System.Web.UI.Page的页面基类
- 继承System.Web.UI.Page的页面基类 生命周期
- 非静态的字段、方法或属性“System.Web.UI.Page.ClientScript.get”要求对象引用
- web基础类(继承System.Web.UI.Page)的问题解决方案~
- 继承System.Web.UI.Page的页面基类