在基类和派生类中执行page_load的顺序 [英] order of execution of page_load in a base and derived classes

查看:65
本文介绍了在基类和派生类中执行page_load的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




i有一个派生自System.Web.UI.Page的类,这是我在我的应用程序中使用的

类作为PageBase。

所有其他页面类都来自我的PageBase而不是原始的
System.Web.UI.Page,以便在页面基础中进行常见检查。


i在页面基页page_load事件中进行securirty检查。

如果安全性失败,我可以在真实之前做任何我想做的事情。 /派生

页面被执行。


但我注意到派生页面加载事件在
$ b $之前被调用b基页加载事件。


所以我有一个问题。


i可以取消在我的派生页面中使用page_load,但是我使用这个

函数检查没有服务器的PostBack事件(比如按钮)

事件处理程序,但是我什么时候将它移动到?


这是正确的执行顺序 - 派生在

基础之前调用吗?


这也是执行的顺序在继承中或仅与委派的

事件处理程序? (我的意思是当你使用Page.onLoad的语法+ =

this_onLoad)....


TIA,z。

解决方案




我从来没有遇到过这种情况,但我要尝试的第一件事就是

Form.OnInit将base.OnInit移动到方法的开头,然后

注册当前页面的Load处理程序。


欢呼,


-

Ignacio Machin,

ignacio.machin at dot.state.fl.us

佛罗里达州交通局


" z。 F"。 <滋** @ info-scopeREMSPAM.co.il>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP10.phx.gbl ...



我有一个派生自System.Web.UI.Page的类,这是我在我的应用程序中用作PageBase的类。
所有其他页面类都是派生自我的PageBase而不是
原始的System.Web.UI.Page,以便在页面基础中进行常见检查。

我在页面基页page_load事件中进行了securirty检查。如果安全失败,我可以在真实之前做任何我想做的事情。 /
派生页面将被执行。

但我注意到派生页面加载事件在基页加载事件之前被称为

<我有一个问题。

我可以取消在派生页面中使用page_load,但是我使用这个
函数来检查没有服务器的PostBack事件(比如
按钮)事件处理程序,但是什么时候我会将它移动到?

这是正确的执行顺序 - 派生在
基础之前调用吗?

这也是继承执行的顺序,还是只有委托的
事件处理程序? (我的意思是当你使用Page.onLoad + =
this_onLoad的语法时)....

TIA,z。



请不要交叉发帖。


我假设你正在使用C#''因为你不会有这种行为在

VB ....无论如何,最简单的解决方案是在Web窗体设计器生成的代码中进入你的派生页面'

OnInit函数。区域,并且更改

两次执行的顺序:

InitializeComponent();

base.OnInit(e);





base.OnInit(e);

InitializeComponent();


这将导致基页的init首先加载,这将导致它'

加载事件首先被连接,从而导致它首先被激活。


Karl


" z。 F"。 <滋** @ info-scopeREMSPAM.co.il>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP10.phx.gbl ...



我有一个派生自System.Web.UI.Page的类,这是我在我的应用程序中用作PageBase的类。
所有其他页面类都是派生自我的PageBase而不是
原始的System.Web.UI.Page,以便在页面基础中进行常见检查。

我在页面基页page_load事件中进行了securirty检查。如果安全失败,我可以在真实之前做任何我想做的事情。 /
派生页面将被执行。

但我注意到派生页面加载事件在基页加载事件之前被称为

<我有一个问题。

我可以取消在派生页面中使用page_load,但是我使用这个
函数来检查没有服务器的PostBack事件(比如
按钮)事件处理程序,但是什么时候我会将它移动到?

这是正确的执行顺序 - 派生在
基础之前调用吗?

这也是继承执行的顺序,还是只有委托的
事件处理程序? (我的意思是当你使用Page.onLoad + =
this_onLoad的语法时)....

TIA,z。



你好再次


我不太确定以前的答案会解决问题,IIRC

订单处理程序的执行没有定义。因此,即使你ou

首先注册父母,你也可以首先获得派生执行。


因此你必须使用另一种方法,你可以使用您在OnLoad事件中调用的虚拟方法

,因此每个类Page)定义需要检查的内容,以便首先验证父级是否具有第一个

行调用父方法:

受保护覆盖​​检查()

{

parent.Check();

//进行检查

}


我认为这样可以解决您的问题。

干杯,


-

Ignacio Machin,

ignacio.machin at dot.state.fl.us

佛罗里达州交通局


" z。 F"。 <滋** @ info-scopeREMSPAM.co.il>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP10.phx.gbl ...



我有一个派生自System.Web.UI.Page的类,这是我在我的应用程序中用作PageBase的类。
所有其他页面类都是派生自我的PageBase而不是
原始的System.Web.UI.Page,以便在页面基础中进行常见检查。

我在页面基页page_load事件中进行了securirty检查。如果安全失败,我可以在真实之前做任何我想做的事情。 /
派生页面将被执行。

但我注意到派生页面加载事件在基页加载事件之前被称为

<我有一个问题。

我可以取消在派生页面中使用page_load,但是我使用这个
函数来检查没有服务器的PostBack事件(比如
按钮)事件处理程序,但是什么时候我会将它移动到?

这是正确的执行顺序 - 派生在
基础之前调用吗?

这也是继承执行的顺序,还是只有委托的
事件处理程序? (我的意思是当你使用Page.onLoad + =
this_onLoad的语法时)....

TIA,z。



Hi,

i have a class that is derived from System.Web.UI.Page, and this is the
class i use in my application as PageBase.
all other page classes are deriverd from my PageBase instead of the original
System.Web.UI.Page in order to have common checks in the page base.

i make securirty checks in the page base page_load event.
if the security fails, i can do whatever i want before the "real" / derived
page gets to be executed.

but i have noticed that the derived page load event gets to be called before
the base page load event.

so i have a problem.

i can cancel the use of page_load in my derived pages, but i use this
function to check on PostBack events that does not have server (like button)
event handler, but there when will i move it to?

is this the correct execution order - the derived gets to called before the
base?

is this also the order of execution in inheritence or only with delegated
event handlers? ( i mean when you use the syntax of Page.onLoad +=
this_onLoad )....

TIA, z.

解决方案

Hi,

I have never been in this situation, but the first thing I would try is in
the Form.OnInit move the base.OnInit to the start of the method, before
register the Load handler for the current page.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"z. f." <zi**@info-scopeREMSPAM.co.il> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...

Hi,

i have a class that is derived from System.Web.UI.Page, and this is the
class i use in my application as PageBase.
all other page classes are deriverd from my PageBase instead of the original System.Web.UI.Page in order to have common checks in the page base.

i make securirty checks in the page base page_load event.
if the security fails, i can do whatever i want before the "real" / derived page gets to be executed.

but i have noticed that the derived page load event gets to be called before the base page load event.

so i have a problem.

i can cancel the use of page_load in my derived pages, but i use this
function to check on PostBack events that does not have server (like button) event handler, but there when will i move it to?

is this the correct execution order - the derived gets to called before the base?

is this also the order of execution in inheritence or only with delegated
event handlers? ( i mean when you use the syntax of Page.onLoad +=
this_onLoad )....

TIA, z.



Please don''t cross-post.

I''m assuming you are using C# ''cuz you wouldn''t have this behaviour in
VB....anyways, the simplest solution is to go into your derived page''s
OnInit function in the "Web Form Designer generated code" region, and change
the order of the two executions:

InitializeComponent();
base.OnInit(e);

to

base.OnInit(e);
InitializeComponent();

This will cause the base page''s init to load first, which will cause it''s
Load event to get hooked up first, thus causing it to fire first.

Karl

"z. f." <zi**@info-scopeREMSPAM.co.il> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...

Hi,

i have a class that is derived from System.Web.UI.Page, and this is the
class i use in my application as PageBase.
all other page classes are deriverd from my PageBase instead of the original System.Web.UI.Page in order to have common checks in the page base.

i make securirty checks in the page base page_load event.
if the security fails, i can do whatever i want before the "real" / derived page gets to be executed.

but i have noticed that the derived page load event gets to be called before the base page load event.

so i have a problem.

i can cancel the use of page_load in my derived pages, but i use this
function to check on PostBack events that does not have server (like button) event handler, but there when will i move it to?

is this the correct execution order - the derived gets to called before the base?

is this also the order of execution in inheritence or only with delegated
event handlers? ( i mean when you use the syntax of Page.onLoad +=
this_onLoad )....

TIA, z.



Hi again

I''m not very sure that the previous answer will solve the problem, IIRC
the order of execution of the handlers is not defined. therefore even ify ou
register first the parent you may get the derived executing first after all.

Therefore you have to use another approach, you could use a virtual method
that you call in the OnLoad event, so each class Page) define what needs to
be checked , being the trick to verify the parent first to have the first
line calling the parent method:
protected override Check()
{
parent.Check();
//do the checking
}

I think this will solve your problem.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"z. f." <zi**@info-scopeREMSPAM.co.il> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...

Hi,

i have a class that is derived from System.Web.UI.Page, and this is the
class i use in my application as PageBase.
all other page classes are deriverd from my PageBase instead of the original System.Web.UI.Page in order to have common checks in the page base.

i make securirty checks in the page base page_load event.
if the security fails, i can do whatever i want before the "real" / derived page gets to be executed.

but i have noticed that the derived page load event gets to be called before the base page load event.

so i have a problem.

i can cancel the use of page_load in my derived pages, but i use this
function to check on PostBack events that does not have server (like button) event handler, but there when will i move it to?

is this the correct execution order - the derived gets to called before the base?

is this also the order of execution in inheritence or only with delegated
event handlers? ( i mean when you use the syntax of Page.onLoad +=
this_onLoad )....

TIA, z.



这篇关于在基类和派生类中执行page_load的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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