如何在全局级别处理OnInit() [英] How to handle OnInit() at global level

查看:108
本文介绍了如何在全局级别处理OnInit()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写下面的代码,但我的网页应用程序中没有母版页。

在每个页面上编写这个代码非常困难。有没有解决方法。

I want to write below code but there is no master page in my web application.
It is very difficult to write this code at each page.Is there any solution for this.

protected override void OnInit(EventArgs e) {
  ViewStateUserKey = Session.SessionID;
  base.OnInit(e);
}

推荐答案

你可以做一件事。添加一个添加此代码的基类。继承该基类的每一页。



例如,您的类后面的代码就像继承 System.Web .UI.Page ...

You can do one thing. Add a base class in which add this code. Inherit every page from that Base Class.

For example, your code behind class is like inheriting System.Web.UI.Page...
public partial class someClassName : System.Web.UI.Page
{
    //....
}



而不是上述内容,你会写...


Instead of the above, you will write...

public partial class someClassName : BaseClass
{
    //....
}


这篇关于如何在全局级别处理OnInit()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆