简体   繁体   English

如何在 ASP.NET AJAX 中执行页面初始化功能?

[英]How to do page initialization functions in ASP.NET AJAX?

There seem to be a number of weird things one could do if one wanted, for hooking up page-load type events.如果需要,似乎有许多奇怪的事情可以做,用于连接页面加载类型的事件。 Here are some specific questions:以下是一些具体问题:

  1. I know about the auto-hooked-up pageLoad function.我知道自动连接的pageLoad函数。 Are there any others like it?还有其他类似的吗?
  2. Where do I hook up events like those from, eg, Sys.Application.add_init or Sys.WebForms.PageRequestManager.getInstance().addPageLoading ?我在哪里连接事件,例如来自Sys.Application.add_initSys.WebForms.PageRequestManager.getInstance().addPageLoading
  3. What's the difference between the first two of those and pageLoad , if any?如果有的话,前两个和pageLoad之间有什么区别?
  4. Rather importantly, what is the "correct" way to be sure that the ASP.NET AJAX files are all loaded before you start hooking up event handlers, processing the page, etc.?更重要的是,在开始连接事件处理程序、处理页面等之前,确保 ASP.NET AJAX 文件都已加载的“正确”方法是什么? My current approach is to use the auto-hooked-up pageLoad to hook up the rest, but this seems kind of hacky.我目前的方法是使用自动连接的pageLoad来连接其余的,但这似乎有点麻烦。
  1. The built-in pageLoad function is just a shortcut to the Sys.Application.load event.内置的 pageLoad 函数只是 Sys.Application.load 事件的快捷方式。 There is another one - pageUnload.还有另一个 - pageUnload。 Find more info here . 在此处查找更多信息。
  2. You can hook those events up almost whenever you like - using the pageLoad function, invoking the add_init/add_load method inside a script block or calling ScriptManager.RegisterStartupScript from server-side.您几乎可以随时连接这些事件 - 使用 pageLoad 函数,调用脚本块内的 add_init/add_load 方法或从服务器端调用 ScriptManager.RegisterStartupScript。 Just make sure you call that JavaScript within the form tag (see #4).只要确保你在表单标签中调用了 JavaScript(见 #4)。 By default all those events occur after the page is loaded so your code should have already been executed by then.默认情况下,所有这些事件都在页面加载后发生,因此您的代码应该已经被执行了。
  3. Technically there should be no difference between using pageLoad and the load event - the first is just easier to hook up.从技术上讲,使用 pageLoad 和 load 事件之间应该没有区别 - 第一个更容易连接。
  4. By default the ASP.NET Ajax script files are rendered just after the beginning of the form tag.默认情况下,ASP.NET Ajax 脚本文件在表单标记开始之后呈现。 This means that those files will get loaded before any other JavaScript statement defined within the form tag gets executed.这意味着这些文件将在表单标签中定义的任何其他 JavaScript 语句被执行之前被加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM