All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
用XML和XSL来生成动态页面_[XML教程]
Sql Server 2005 数据库维护计划_[SQL Server教程]
SQL,Server,中易混淆的数据类型_[SQL,Server教程]
C#中ArrayList.CopyTo
学习动态网页技术PHP中错误处理的一些方法_[PHP教程]
asp.net控件用法--在Repeater中嵌套使用Repeater_[Asp.Net教程]
常规数据库维护涉及的5项工作_[SQL Server教程]
ASP.NET,2.0,中的窗体身份验证_[Asp.Net教程]
小结:PHP动态网页程序两个有用的小技巧_php资料_编程技术
js也可以有自定义事件,注入就是这么爽_.net资料_编程技术
Reading number is top 10 pictures
Terrorist smile the largest human history an explosion1
The service WaLiangGe Chinese aircraft carrier1
赵惟依写真2
10 powerless things in life
红楼梦金陵十二钗(1)
XuYing poker perspective garment debut
美奂绝伦的风景
Japanese snow monkeys in the hot spring to keep warm, close their eyes to enjoy
BingBingFan apple dew point photo gallery3
Photographed the passion of the clients and prostitutes in the sex trade picture1
Download software ranking
尖东毒玫瑰A
网页特效实例大全
1400篇各类破解文章
尖东毒玫瑰B
Unix video tutorial14
Love the forty days
Unix video tutorial2
Tram sex maniac 2 (H) rar bag15
Boxer vs Yellow3
White deer villiage
归海一刀 published in(发表于) 2014/1/30 1:10:42 Edit(编辑)
新瓶旧酒ASP.NET,AJAX(1),-,简单地过一下每个控件_[Asp.Net教程]

新瓶旧酒ASP.NET,AJAX(1),-,简单地过一下每个控件_[Asp.Net教程]

新瓶旧酒ASP.NET AJAX(1) - 简单地过一下每个控件_[Asp.Net教程]

新瓶旧酒ASP.NET AJAX(1) - 简单地过一下每个控件(ScriptManager、ScriptManagerProxy、UpdatePanel、 UpdateProgress和Timer)



介绍
ASP.NET AJAX就5个控件,分别是ScriptManager、ScriptManagerProxy、UpdatePanel、UpdateProgress和Timer。先简单地过一下。



关键
1、ScriptManager 和ScriptManagerProxy
·一个页只能有一个ScriptManager(包含了所有脚本资源),要放到任何用到AJAX的控件的前面。
·如果把它放到母版页,而内容页需要与其不同的配置的话,则应在内容页使用ScriptManagerProxy。
·ScriptManager默认EnablePartialRendering="true"。
·ScriptManager的 AllowCustomErrorsRedirect="true"的时候,出现异常就会转到web.config里customErrors中defaultRedirect所指的地址。


2、 UpdatePanel
·UpdatePanel内放置需要被刷新的控件,如果是其内部控件事件导致其刷新,则不用另外做什么设置,因为UpdatePanel默认ChildrenAsTriggers="true"。
·如果是UpdatePanel外部控件导致其刷新的话,则应设置 Triggers。
·在Triggers内,如果AsyncPostBackTrigger未设置EventName,则为其指定控件的默认事件。
·UpdatePanel默认UpdateMode="Always",需要的话应设置UpdateMode="Conditional"。
·RenderMode="Block"对应div;RenderMode="Inline"对应span


3、UpdateProgress
·默认,任何回发,当有延迟的时候则显示UpdateProgress里的ProgressTemplate。
·要与某UpdatePanel关联则设置 AssociatedUpdatePanelID属性。
·DynamicLayout为true则用“display:none;”隐藏;DynamicLayout为false则用 “visibility:hidden;”隐藏。
·默认情况下,例如有2个异步回发,如果第1个还没有执行完毕就执行第2个的话,则会先取消第1个异步回发。


4、Timer
·Interval:间隔时间,单位(毫秒);每一个间隔时间后将触发 Tick事件。
·Timer要放在其所刷新的UpdatePanel内部;放外面的话要设置UpdatePanel的Triggers。


5、其它
·要在UpdatePanel中使用Validator的话,请参看http://blogs.msdn.com/mattgi/archive/2007/01/23/asp-net-ajax-validators.aspx
·内容页获取母版页的ScriptManager:ScriptManager.GetCurrent(Page)
·后置代码处对UpdatePanel编程,例: ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(this.Button1); ScriptManager.GetCurrent (this).RegisterPostBackControl(this.Button2); this.UpdatePanel1.Update();
·Internet Explorer Developer Toolbar下载
·Fiddler下载
·Web Development Helper下载



示例
1、最简单的示例
<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Sample.aspx.cs"
Inherits="Overview_Sample" Title="最简单的示例" %>




  • 之前要有ScriptManager(包含了所有脚本资源),我把它放到母版页了。内容页如需不同配置则应使用ScriptManagerProxy。

  • 最简单的示例,拖个UpdatePanel进来。在 UpdatePanel内拖个GridView,并设置其数据源即可。




DataSourceID ="SqlDataSource1">

& nbsp;




DeleteCommand="DELETE FROM [Products] WHERE [ProductID] = @ProductID" InsertCommand="INSERT INTO [Products] ([ProductName], [QuantityPerUnit], [UnitPrice], [Discontinued]) VALUES (@ProductName, @QuantityPerUnit, @UnitPrice, @Discontinued)"
SelectCommand="SELECT [ProductID], [ProductName], [QuantityPerUnit], [UnitPrice], [Discontinued] FROM [Products]"
UpdateCommand="UPDATE [Products] SET [ProductName] = @ProductName, [QuantityPerUnit] = @QuantityPerUnit, [UnitPrice] = @UnitPrice, [Discontinued] = @Discontinued WHERE [ProductID] = @ProductID">


















2、UpdatePanel
<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="UpdatePanel.aspx.cs"
Inherits="Overview_UpdatePanel" Title="UpdatePanel" %>




  • UpdatePanel内放置需要被刷新的控件,如果是其内部控件事件导致其刷新,则不用另外做什么设置,因为UpdatePanel默认ChildrenAsTriggers="true"。

  • 如果是UpdatePanel外部控件导致其刷新的话,则应设置Triggers。

  • 在Triggers内,如果AsyncPostBackTrigger 未设置EventName,则为其指定控件的默认事件。

  • UpdatePanel默认UpdateMode="Always",需要的话应设置UpdateMode="Conditional"。

  • RenderMode="Block"对应div; RenderMode="Inline"对应span





我在UpdatePanel里





<%--如果没设置 EventName,则取默认事件,Button的默认事件为Click-- %>





&nbsp;



我在UpdatePanel外
onClick="Button1_Click" />


&nbsp;


<%--嵌套UpdatePanel-- %>



外围UpdatePanel

onClick="Button2_Click" />

& nbsp;
& nbsp;

& nbsp; 嵌套UpdatePanel
& nbsp;
& nbsp; onClick="Button3_Click" />
& nbsp;

& nbsp;






3、UpdateProgress
<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="UpdateProgress.aspx.cs"
Inherits="Overview_UpdateProgress" Title="UpdateProgress" %>




  • 默认,任何回发,当有延迟的时候则显示 UpdateProgress里的ProgressTemplate。

  • 要与某UpdatePanel关联则设置 AssociatedUpdatePanelID属性。

  • DynamicLayout为true则用“display:none; ”隐藏;DynamicLayout为false则用“visibility:hidden;”隐藏。

  • 默认情况下,例如有2个异步回发,如果第1 个还没有执行完毕就执行第2个的话,则会先取消第1个异步回发。





UpdatePanel1



onClick="Button1_Click" />



DynamicLayout="false">


UpdatePanel1更新中





&nbsp;





UpdatePanel2



onClick="Button2_Click" />



DynamicLayout="true">


UpdatePanel2更新中





&nbsp;





UpdatePanel3


onClick="Button3_Click" />





有延迟我就更新



4、Timer
<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Timer.aspx.cs"
Inherits="Overview_Timer" Title="Timer" %>




  • Interval:间隔时间,单位(毫秒);每一个间隔时间后将触发Tick事件

  • Timer要放在其所刷新的UpdatePanel内部;放外面的话要设置UpdatePanel的Triggers。





UpdatePanel1


& nbsp;内部Timer
& nbsp;
& nbsp;







注:以上示例涉及到后置代码的,其作用都是用来刷新相关的Label的,所以略掉了。

作者:webabcd

[源码下载]







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.