ASP.NET 页面中应该在哪里完成操作?
我对 ASP.NET 非常陌生,在对 一些问题,我想知道我是否做错了(我有这样做的坏习惯)。 我有兴趣了解 ASP.NET 的运作方式。
我的问题是:在哪里可以找到文档来指导我决定在哪里进行哪些处理?
作为一些具体示例(我对这些问题的答案很感兴趣,但我宁愿指出提供更一般答案的资源):
- 我应该在
Page_Load
中进行哪些处理? - 我应该对
Load
事件进行什么处理? - 我可以在
Page_Unload
中做什么? - 事情按什么顺序完成?
- 每个事件何时触发?
- 什么是页面生命周期?
编辑:这个问题可能对某些人也有用。
I'm very new to ASP.NET and, after beating my head on a few problems, I'm wondering if I'm doing things wrong (I've got a bad habit of doing that). I'm interested in learning about how ASP.NET operates.
My question is: Where can I find documentation to guide me in deciding where to do what processing?
As a few specific examples (I'm interested in answers to these but I'd rather be pointed at a resource that gives more general answers):
- What processing should I do in
Page_Load
? - What processing should I do with the
Load
event? - What can I do in
Page_Unload
? - What order do things get done in?
- When is each event fired?
- What is the page life-cycle?
edit: this question might also be of use to some people.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
ASP.net 页面生命周期
ASP.net page lifecycle
我绝对推荐您阅读以下内容:
http://www.west-wind。 com/presentations/howaspnetworks/howaspnetworks.asp
如果您是 ASP.NET 的新手,那么您在获取所有这些内容时会遇到一些困难,但实际上,我还没有找到关于该主题的如此详细的文档,来自MS 文档或任何 MS 员工博客。
我用困难的方式做到了这一点,并遵循了我可以使用反汇编代码的每一条路径,但那个人确实花了时间来编写它。
I would definitely recommend you reading this:
http://www.west-wind.com/presentations/howaspnetworks/howaspnetworks.asp
If you're new to asp.net you'll have some trouble getting all of that, but really, I have yet to find such a detailed document on the topic comming from ms documentation or any ms employee blog.
I did it the hard way and followed every path I could using disassembled code but that guy really took the time to write it.
基本上尝试在
Page_Load
中执行此操作,如果这不起作用,请在Page_Init
或Page_Render
中尝试。 通常其中之一是有效的:)这就是科学方法。Basically try and do it in
Page_Load
and if that doesn't work, try it in eitherPage_Init
orPage_Render
. Normally one of them works :) That's the scientific approach.不同的人发布的链接确实非常有帮助 - ASP.NET 页面生命周期确实并不总是那么容易理解和掌握!
重要的建议 - 我建议优先选择重写的方法而不是“神奇”附加的方法,例如,更喜欢“
为什么
”? 简单:在重写的方法中,您可以自己指定是否以及何时调用基本方法:
或:
甚至:
甚至:
在 Page_Load() 版本中没有这种灵活性。
马克
The links posted by various folks are very helpful indeed - the ASP.NET page life cycle really isn't always easy to grok and master!
On nugget of advice - I would recommend preferring the overridden methods vs. the "magically" attached methods, e.g. prefer the
over the
Why? Simple: in the overridden methods, you can specify yourself if and when the base method will be called:
or:
or even:
or even:
You don't have that flexibility in the Page_Load() version.
Marc
为了能够理解您刚才提出的问题,您需要学习的第一件事是:页面生命周期。 有时这很糟糕,尤其是 ViewState 部分。
•在Page_Load中我应该做什么处理?
•我应该如何处理Load事件? = Page_load
•我可以在Page_Unload 中做什么? 清理
• 事情按什么顺序完成? 页面生命周期
•每个事件何时触发? 页面生命周期
•什么是页面生命周期?
编辑: 图片来源:http:// www.eggheadcafe.com/articles/20051227.asp
更多信息:http: //www.codeproject.com/KB/aspnet/PageLifeCycle.aspx
The first thing you need to learn to be able to understand the the questions you just asked is: PAGE LIFE CYCLE. It is a bitch sometimes, especially the ViewState part.
•What processing should I do in Page_Load?
•What processing should I do with the Load event? = Page_load
•What can I do in Page_Unload? Clean up
•What order do things get done in? PAGE LIFE CYCLE
•When is each event fired? PAGE LIFE CYCLE
•What is the page life-cycle?
Edit: Image source: http://www.eggheadcafe.com/articles/20051227.asp
More info: http://www.codeproject.com/KB/aspnet/PageLifeCycle.aspx
这里有一些很好的链接可以帮助您入门。 了解 ASP.NET 生命周期如何组合在一起对于理解代码如何与之交互至关重要。
ASP.NET 页面生命周期概述:
ASP.NET 页面生命周期:
Here are some good links to get you started. Understanding how the ASP.NET life-cycle fits together is critical to understanding how your code will interact with it.
ASP.NET Page Life Cycle Overview:
The ASP.NET Page Life Cycle: