是否有任何网页在您的应用程序加载的任何时间被调用的函数?您的、应用程序、函数、有任何

2023-09-03 15:58:58 作者:她会发光我会反光i

我希望能够运行任何时候任何页面在加载应用程序的脚本。有没有什么地方我可以简单地添加呢?或者,我必须添加code在每一个页面加载?

I want to be able to run a script anytime ANY page is loaded in the application. Is there somewhere I can simply add this? Or do I have to add the code in every page load?

推荐答案

您可以做的三件事之一:

You can do one of three things:

使用的 基页 在你的应用程序,并在应用程序中的所有网页继承它。在基页的Page_Load事件中,做你应该做的事情。请确保你的应用程序中的继承页面调用基页的Page_Load事件,如果他们覆盖的Page_Load (他们通常做的)。而由于Page_Load中被过度使用,我给了相关意见,看看所有页面事件(尤其是特别的 PAGE_ prerender )的情况下,另一种是比较合适的。

Use a base page in your application, and have all the pages in your application inherit from it. In the page_load event in the base page, do what you have to do. Make sure that the inheriting pages in your app call the base page's page_load event if they override page_load (they usually do). And because page_load is over-used, I'll give the related advice to look at all the page events (especially especially page_prerender) in case another is more appropriate.

使用的那团火在 的Global.asax 事件页,每当接收到一个请求而发生。退房的Application_BeginRequest事件。但是,还有一堆的事件的出现,让检查他们全力以赴的情况下另一个事件是更适用于您的情况。 (就像普通页面的事件,不要在始终使用同一事件的坏习惯。)

Use the events that fire in the global.asax page, which happen whenever a request is received. Check out the Application_BeginRequest event. But, there's a bunch of events there, so check them all out in case another event is more applicable to your situation. (Just like the regular page events, don't get in the bad habit of always using the same event.)

有一个机会,你想有发生,每次都应该有一个的母版页 ,尤其是如果它的布局有关。母版页看起来娇媚但在良好的设计证明了自己。如果您使用的是母版页的Page_Load事件的常用功能,你不必从每个内容页面的Page_Load中调用它;它激发每次被叫页面后的Page_Load事件。 (我提到这一点,因为它很容易母版页和基页起初混淆。)

There's a chance that what you want to have happen each time should go into a master page, especially if it's layout related. Master pages seem cutesy but have proved themselves in good designs. If you use a master page's page_load event for common functionality, you don't have to call it from each content page's page_load; it fires every time after the called-page's page_load event. (I mention this because it's easy to confuse master pages and base pages at first.)

 
精彩推荐
图片推荐