当页面使用母版页时,设计时创建的控件将被初始化?

发布于 2024-08-18 02:02:52 字数 457 浏览 3 评论 0原文

http://www.allinterview.com/showanswers/73327.html


a)如果我正确理解了上面的文章,那么当一个页面有一个与之关联的母版页时,那么在设计时创建的所有控件(在母版页中声明的控件和在内容页中声明的控件)仅在 Init 期间分配声明性值事件?

b) 假设我们的页面与母版页相关联并且还使用主题 -->皮肤文件也在 Init 事件期间应用,因此我假设在 Init 事件期间 Asp.Net 首先将控件初始化为其声明值,然后才将皮肤规则应用于它们?

c) 但是,如果页面不使用母版页,那么它在设计时声明的控件会在 Init 事件之前分配值吗?


谢谢

http://www.allinterview.com/showanswers/73327.html

a) If I understand the above article correctly, then when a page has a master page associated with it, then all controls ( those declared in master page and those declared in content page ) created during design time are assigned declarative values only during an Init event?

b) Assuming our page is associated with Master page and also uses a theme --> skin files are also applied during an Init event, so I assume that during an Init event Asp.Net first initializes controls to their declarative values and only then applies skin rules to them?

c) But if a page doesn’t use a master page, then the controls it declares during design time are assigned values prior to Init event?

thanx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦纸 2024-08-25 02:02:52

这是 MSDN 上有关此内容的更好文章。向下滚动到生命周期事件。

如果我正确理解你的问题,你在 a、b 和 c 中提出的所有问题都发生在 Pre_Init 期间。 Init 事件在 Pre_Init 期间初始化所有控件后触发。因此,在 Init 期间您现在可以读取或初始化这些控件的属性。

请注意,您仍在 Init 期间“初始化”控件的属性。

示例...

<asp:Label ID="Label1" runat="server" CssClass="someclass"></asp:Label>

Init:
Label1.CssClass = "someotherclass";

如果我错了,请纠正我...

我相信 Label1 在 Pre_Init 期间使用 CssClass 设置为“someclass”进行初始化,然后 Label1 的 CssClass 重新初始化(初始值已更改)为“someotherclass”。因此,当页面加载时,类值将是“someotherclass”。

并且尝试在 Pre_Init 块中访问 Label1.CssClass 将不起作用,因为 Label1 尚未完成初始化。您可以从 Init 访问控制属性。

无论您是否有 MasterPage,此初始化顺序都不会改变。将 MasterPage 视为另一个控件。我相信 MasterPage 内部的所有控件也在 Pre_Init 期间初始化。

希望这一点是清楚的。

Here's a better article about this on MSDN. Scroll down to Life-cycle Events.

If I'm understanding your questions correctly, all you are asking in a, b, and c happen during Pre_Init. Init event fires after all controls are initialized during Pre_Init. So, during Init you can now read or initialize those controls' properties.

Note that you are still "initializing" control's property during Init.

Example...

<asp:Label ID="Label1" runat="server" CssClass="someclass"></asp:Label>

Init:
Label1.CssClass = "someotherclass";

Correct me if I'm wrong guys...

I believe Label1 is initialzed with CssClass set to "someclass" during Pre_Init and then Label1's CssClass is re-initiazed (initial value is changed) to "someotherclass". So when page is loaded class value will be "someotherclass".

And trying to get access to Label1.CssClass within Pre_Init block won't work since Label1 is not yet done initializing. You have access to control properties from Init.

This initialization order does not change whether you have MasterPage or not. Consider MasterPage as just another control. I believe all controls inside of MasterPage are also initialized during Pre_Init.

Hope this is clear.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文