很多时候我们需要在页面加载以后立刻调用一些Web Service,比如一个客户端的Atlas ListView会在加载后立刻得到初始化的填充数据。虽然这可以使用Atlas的InitialData控件完成,但对于其它的一些要求,比如在页面加载后立刻执行一段Atlas脚本(其中用到了Atlas对JavaScript的扩展),我们仍需要一个页面加载的事件来触发这些操作。
很多朋友采用如下的两种方法:
- 直接在页面的Script段中书写要执行的脚本。
- 在页面的onload JavaScript事件处理方法中书写。
这些都是不正确的方式,会有错误发生,原因很简单:Atlas的客户端实现也是一段JavaScript,需要先执行一次才可以工作,而上述两种方法的语句都是在Atlas客户端实现被初始化前运行的,自然会导致错误。
Atlas充分意识到了这个需求,提供了Framework内部的OnLoad事件,该事件将在Atlas Framework初始化以后被引发。想捕获这个事件,您需要在页面的Atlas XML Script中声明:
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
其中application 作为当前运行的Atlas 程序的引用,提供了一个load 事件,这样我们通过指定它的事件处理函数,即可在Atlas Framework 初始化之后执行我们的代码。
下面来看一个例子,Web Service如下,还是简单的两个数相加:
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](/Images/OutliningIndicators/ContractedBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![ExpandedBlockEnd.gif](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
然后ASPX 页面中添加ScriptManager 并对上述Web Service 进行引用:
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
- $()方法,等同于document.getElementById()
- Sys.UI.TextBox类,封装了HTML的input元素
- 对Web Service调用的Mashup
![None.gif](/Images/OutliningIndicators/None.gif)
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](/Images/OutliningIndicators/ContractedBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![ExpandedBlockEnd.gif](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](/Images/OutliningIndicators/ContractedBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![ExpandedBlockEnd.gif](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
运行结果,没有任何问题:
本实例的源代码可以在此下载:http://files.cnblogs.com/dflying/ApplicationLoadEventDemo.zip