C#中的页面加载

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16294413/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 00:40:12  来源:igfitidea点击:

Page_Load in C#

c#pageload

提问by Sudha

I am working with C# web application. I want to know deeply about the page events. Because I thought that the page load event happens first (when a page is requested in browser). But when I tried with commenting the method protected void Page_Load(object sender, EventArgs e)the page get loaded without error.

我正在使用 C# Web 应用程序。我想深入了解页面事件。因为我认为页面加载事件首先发生(当在浏览器中请求页面时)。但是当我尝试评论该方法时protected void Page_Load(object sender, EventArgs e),页面加载时没有错误。

采纳答案by Newton Sheikh

off-course your webpage will work even if there is no Page_Load() method. Before a Page_Load() events like PreInit, Init() etc are called. Refer to page life cycle.

即使没有 Page_Load() 方法,您的网页也可以正常工作。在调用 PreInit、Init() 等 Page_Load() 事件之前。请参阅页面生命周期。

Page_Load() method is called after a preLoad event. With Page_Load() you can set default values or check for postBacks etc.

Page_Load() 方法在 preLoad 事件之后调用。使用 Page_Load() 您可以设置默认值或检查 postBacks 等。

 protected void Page_Load(object sender, EventArgs e)
    {
        int x = 10;
    }

write this and put a break-point on int x = 10; watch sender and e.

写这个并在 int x = 10 上放置一个断点;看发件人和e。

回答by Freelancer

1.Page request

2.Start

3.Initialize

4.Load

5.Postback Event Handling

6.Rendering

7.Unload

This is the page life cycle.

这就是页面生命周期。

Load event comes at 4th position.

加载事件出现在第 4 位。

You can check details over here:

您可以在此处查看详细信息:

http://msdn.microsoft.com/en-us/library/ms178472%28v=vs.100%29.aspx

http://msdn.microsoft.com/en-us/library/ms178472%28v=vs.100%29.aspx

回答by Lingasamy Sakthivel

Every Page object has nine events, most of which you will not have to worry about in your day to day dealings with ASP.NET. The three that you will deal with the most are:

每个 Page 对象都有nine events,您在日常与 ASP.NET 打交道时不必担心其中的大部分。您将处理最多的三个是:

Page_Init
Page_Load
Page_PreRender

They do execute in the order given aboveso make sure to take that into consideration, especially when building custom controls. The reason you have to keep this in mind is because information might not be available when you expect if you do not deal with it appropriately.

它们确实按照上面给出的顺序执行,所以一定要考虑到这一点,尤其是在构建自定义控件时。您必须牢记这一点的原因是,如果您不适当地处理信息,则可能无法在您期望的时候获得信息。

Refer: Life Cycle

参考:生命周期