从调用内联code原有的Page_Load功能 [英] Calling the original Page_Load function from inline code

查看:185
本文介绍了从调用内联code原有的Page_Load功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢猴子修补一个ASPX的网站,这样我可以编译的程序集内添加内容到Page_Load方法。

I like to Monkey patch a ASPX website so that I can add stuff to the Page_Load method within a compiled assembly.

我首先想到的是添加含有第二Page_Load方法的ASPX文件,像这样的脚本标记:

My first thought was to add a script tag containing a second Page_Load method to the ASPX file like so:

<script language="CS" runat="server">
void Page_Load(object sender, System.EventArgs e) 
{
     // do some stuff in addition to the original Page_Load method
}
</script>

但它看起来像只从内嵌code Page_Load方法将被执行,而不是从原来的code-隐藏文件(编译的程序集内)的人。

But it looks like only the Page_Load method from the inline code will be executed and not the one from the original code-behind file (within the compiled assembly).

是否有可能从我的直列code调用原始的方法是什么?或者是有添加的东西,应该直接运行Page_Load方法是从所谓的内联code,而无需修改现有的装配后的任何其他方式?

Is it possible to call the original method from within my inline code? Or is there any other way to add stuff that should run directly after the Page_Load method was called from within inline code without modifying the existing assembly?

推荐答案

在asp.net模型是在.aspx文件中声明的页面actally从它继承自类的子类系统.Web.UI.Page 在.aspx.cs文件中声明。

The asp.net model is that the page declared in the .aspx file is actally a descendant class from the class that inherits from System.Web.UI.Page declared in the .aspx.cs file.

所以,你的Page_Load方法被调用,因为它基本上隐藏了原来的Page_Load方法。下面这个逻辑,你可以这样做:

So your Page_Load method is called because it basically hides the original Page_Load method. Following that logic, you could do:

<script language="CS" runat="server"> 
void Page_Load(object sender, System.EventArgs e)  
{      
   base.Page_Load(sender, e);
   // do some stuff in addition to the original Page_Load method 
} 
</script> 

有没有可访问性问题,因为asp.net默认情况下宣布的Page_Load和类似的方法,如保护这样子类可以调用它。

There are no accessibility issues because asp.net by default declares Page_Load and similar methods as protected so descendant classes can call them.

这篇关于从调用内联code原有的Page_Load功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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