ASP.NET继承的UserControl,事件序列问题
我有一个继承自另一个的 UserControl,我的问题很简单。控件的页面加载首先触发,还是基类页面加载首先触发?
I have a UserControl inheriting from another, and my question is simple. Does the control's page load fire first, or does the base class page load fire first?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
“Page 调用 Page 上的 OnLoad 事件方法,然后递归地对每个子控件执行相同的操作,从而对其每个子控件执行相同的操作,直到加载页面和所有控件。”
通过此链接: http://msdn.microsoft.com/en-us/ library/ms178472.aspx
因此,简单地回答,Page_Load 事件是在用户控件中的 load 事件之前调用的
"The Page calls the OnLoad event method on the Page, then recursively does the same for each child control, which does the same for each of its child controls until the page and all controls are loaded."
From this link: http://msdn.microsoft.com/en-us/library/ms178472.aspx
So to answer plainly, the Page_Load event is called before the load event in user controls
如果您正在谈论实际的继承,而不是控件组合,那么所有标准的面向对象规则都适用。
因为这些不是单独的对象,所以您的控件上只有一个 Load 事件,并且只能有一个 Page_Load 方法,除非您使用 新 修饰符。因此,从本质上讲,子页面加载和父页面加载之间没有区别……它们是一回事。
If you are talking about an actual inheritance, and not control composition, then all the standard Object Oriented rules apply.
Because these are not separate object, there is only one Load event on your control, and there can be only one Page_Load method, unless you explicitly hide it using the new modifier. So, in essence, there is no difference between the Child page load, and the Parent page load... they are one in the same.
我相信控件的 Page_Load 应该首先触发。除了 Page_Init 事件之外,所有其他启动事件都发生在控件层次结构中。
编辑:我错了。页面触发其加载事件,然后在子控件上递归调用它,子控件又在其子控件上递归调用它,依此类推。我的坏...
The control's Page_Load should fire first, I believe. Other than the Page_Init event, all other initiation events occur up the control hierarchy.
Edit: I'm wrong up there. The page fires its load event then recursively calls it on child controls, which recursively call it on its child controls, and so on. My bad...