c# - asp.net 覆盖

标签 c# asp.net

使用标准事件处理程序或覆盖 asp.net 页面的基类的优缺点是什么?有没有?我见过两者都曾经做过同样的事情。

protected void Page_PreInit(object sender, EventArgs e)
{
    //Put your code here
}

protected override void OnPreInit(EventArgs e)
{
    base.OnPreInit(e);
    //Put your code here
}

最佳答案

如果您使用覆盖,您可以决定何时执行自定义函数。在基本方法之后或之前。但如果您使用自动接线事件,它将在基本事件之后执行。

protected override void OnPreInit(EventArgs e)
{
    base.OnPreInit(e);
    //Put your code here
}

protected override void OnPreInit(EventArgs e)
{
    //Put your code here
    base.OnPreInit(e);
}

关于c# - asp.net 覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7776591/

相关文章:

javascript - 没有图像显示

c# - HttpClient PutAsync 不向 api 发送参数

c# - IBackgroundTask 类中的任务类型

c# - 如何利用 EF 和 LINQ 添加过滤器并动态指定表、列、过滤器和排序依据

asp.net - EF4慢关联访问

c# - 从 HTML 链接调用 C# 函数

c# - 动态更改 ASP.NET MVC 中的样式属性

c# - 当仅覆盖一对方法或属性中的一个时显示警告

c# - Request.Url.Port 给出了错误的端口

javascript - 页面上带有 HTML Editor Extender 的回发导致 IE11 中的 JavaScript 错误