您所在的位置: 首页>>读书频道>>设计开发>>.Net系列>>

页面范例1 - 示范如何更新UpdatePanel控件并让它晃动

http://book.51cto.com  2008-05-06 17:00  章立民研究室  机械工业出版社  我要评论(0)

页面范例1 - 示范如何更新UpdatePanel控件并让它晃动

图5-10所示是页面范例CH5_DemoForm004.aspx的执行画面,我们发现,当您使用鼠标单击超级链接“更新UpdatePanel控件并让它晃动”时,将使得两个UpdatePanel控件的内容都被更新,时,两个UpdatePanel控件会各自显示一个红色外框并随后消失而呈现一种晃动的效果。如果您单击超级链接“更新UpdatePanel控件但是不晃动”则只会使得两个UpdatePanel控件的内容被更新,但是并不会有晃动的效果。

 
页面范例CH5_DemoForm004.aspx其实就是采用我们先前所述的技巧来设计的,关键在于下列JavaScript程序代码:
<script type="text/javascript">
Type.registerNamespace("ScriptLibrary");
ScriptLibrary.BorderAnimation = function(color, duration) {
this._color = color;
this._duration = duration;
}
ScriptLibrary.BorderAnimation.prototype = {
animatePanel: function(panelElement) {
var s = panelElement.style;
s.borderWidth = '2px';
s.borderColor = this._color;
s.borderStyle = 'solid';
window.setTimeout(
function() {{ s.borderWidth = 0; }},
this._duration
);
}
}
ScriptLibrary.BorderAnimation.registerClass('ScriptLibrary.BorderAnimation');
var panelUpdatedAnimation = new ScriptLibrary.BorderAnimation('red', 1000);
// 此变量用来跟踪哪一个元素引发异步回送。
var postbackElement;
// 设定当引发beginRequest 事件时便执行事件处理函数beginRequest。
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);
// 设定当引发pageLoaded 事件时便执行事件处理函数pageLoaded。
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded);
function beginRequest(sender, args) {
// 取得引发异步回送的控件并赋给变量postbackElement。
postbackElement = args.get_postBackElement();
}
function pageLoaded(sender, args) {
// 使用PageLoadedEventArgs 类型自变量对象的panelsUpdated 属性来取得一个数组,
// 此数组将内含其内容将被更新的各个UpdatePanel 控件的<div> 标记元素,
// 如果引发异步回送控件的id 属性值内含文本字符串'animate' ,就通过一个循环
// 将数组中每一个<div> 标记元素传递给负责让UpdatePanel 控件晃动起来的函数。
var myUpdatedPanels = args.get_panelsUpdated();
if (typeof(postbackElement) === "undefined") {
return;
}
else if (postbackElement.id.toLowerCase().indexOf('animate') > -1) {
for (i=0; i < myUpdatedPanels.length; i++) {
panelUpdatedAnimation.animatePanel(myUpdatedPanels[i]);
}
}
}
</script>
【责任编辑:夏书 TEL:(010)68476606】

回书目   上一节   下一节
专题:ASP.NET 2.0基础开发指南
.NET移动与嵌入式技术专题
.NET Framework新手入门专题
VS.NET实用开发专题
ADO.NET实用技巧专题
 
 验证码: (点击刷新验证码)   匿名发表
  • Visual C++ 完全自学宝典

  • 作者:强锋科技,朱洪波
  • Visual C++ 6.0是微软公司为程序人员提供的Visual Studio 6.0工具套件中的重要组成部分。本书由浅入深地介绍使用Visual C++ 6.0..
Copyright©2005-2008 51CTO.COM 版权所有