在 ASP.NET 中,当页面加载到客户端浏览器中时会触发哪个事件?
在 ASP.NET 中,当页面加载到客户端浏览器中时会触发该事件。当页面未在客户端浏览器中加载时,会触发 Init、Load、PreRender 事件。
基本上,当页面在客户端浏览器中显示时,我必须做一些工作。
In ASP.NET which event fires when page is loaded in clients browers. Init, Load, PreRender event fires when page is not loaded in clients browser.
Basically I have to some work when page is displayed in client's browser..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能对 Javascript 更感兴趣,而不是 ASP.NET(服务器端代码)(也许使用 jQuery 的 document.ready() 在页面完成加载时运行。)
编辑:我仅使用 ASP.NET 就能想出的最佳答案是 OnLoadComplete()
Instead of ASP.NET (server-side code) you might be more interested in Javascript (perhaps using jQuery's document.ready() which runs when the page has completed loading.)
Edit: The best answer I can come up with using only ASP.NET is OnLoadComplete()
没有这样的事件。要了解其原因,您必须了解 Web 应用程序的工作原理。 ASP.NET 代码在服务器上运行以构建网页内容,然后服务器将内容发送到用户计算机上运行的浏览器。
因此,在浏览器中打开的文档甚至不是 ASP.NET 页面生命周期的一部分。就 ASP.NET 而言,该页面现在是浏览器的问题,并且它已经转移到其他问题上。
打个比方,就像当有人收到您 (ASP.NET) 邮寄给他们的信件时希望得到通知。除非接收者(浏览器)发回某种通信,否则发送者(ASP.NET)无法知道其他地方发生了什么。
如果您想在浏览器加载页面时执行某些操作,则需要编写由浏览器运行的代码。通常,这是以嵌入到页面中的脚本的形式出现的,通常是 JavaScript。
There is no event like that. To understand why you have to understand how a web application works. The ASP.NET code runs on the server to build the contents of the web page, then the server sends the contents down to the browser which is running on the user's machine.
So the document being opened in the browser isn't even part of the ASP.NET page lifecycle. As far as ASP.NET is concerned, that page is now the browser's problem and it has already moved on to something else.
To make an analogy, it is like wanting to be notified when someone receives a letter that you (ASP.NET) mailed to them. Unless the recipient (the Browser) sends back some kind of communication there is no way for the sender (ASP.NET) to know what is happening somewhere else.
If you want to do something when the page is loaded in the browser, you need to write code that is run by the browser. Usually this is in the form of a script embedded in the page, usually in JavaScript.