UpdatePanel控件也是Ajax里用得最多的控件之中的一个,UpdatePanel控件是用来局部更新网页上的内容,网页上要局部更新的内容必须放在UpdatePanel控件里,他必须和上一次说的ScriptManager控件一起使用。如今来看UpdatePanel的属性
指定Button2实现整页更新。
.CS代码为:
protected
void
Button1_Click1(
object
sender, EventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=;database=pubs");
string sql1 = "select top 5 au_lname from authors ";
SqlDataAdapter myAdapter = new SqlDataAdapter(sql1, conn);
DataSet ds = new DataSet();
myAdapter.Fill(ds, "bieminG");
//来自web service的dataset,这里随便一个ds就能够;
this.GridView1.DataSource = ds.Tables["bieminG"].DefaultView; ;
this.GridView1.DataBind(); //数据绑定
}
protected
void
Button2_Click(
object
sender, EventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
this.Label1.Text = "11111";
}
Button1实现一个数据集的异步更新,BUTTON2就是一般的赋值了。看看是不是非常easy呀!呵呵!
UpdatePanel
重要的属性例如以下:
属性
|
说明
|
ChildrenAsTriggers
|
当UpdateMode属性为Conditional时,UpdatePanel中的子控件的异步回送是否会引发UpdatePanle的更新。
|
RenderMode
|
表示UpdatePanel终于呈现的HTML元素。Block(默认)表示<div>,Inline表示<span>
|
UpdateMode
|
表示UpdatePanel的更新模式,有两个选项:Always和Conditional。Always是无论有没有Trigger,其它控件都将更新该UpdatePanel,Conditional表示仅仅有当前UpdatePanel的Trigger,或ChildrenAsTriggers属性为true时当前UpdatePanel中控件引发的异步回送或者整页回送,或是server端调用Update()方法才会引发更新该UpdatePanel。
|
ChildrenAsTriggers:当UpdateMode属性为Conditional时,UpdatePanel中的子控件的异步回送是否会引发UpdatePanle的更新。
里面包括了一个Triggers,里面第一个属性
AsyncPostBackTrigger指定Button1实现异步更新,而PostBackTrigger
RenderMode:表示UpdatePanel终于呈现的HTML元素。Block(默认)表示<div>,Inline表示<span>
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
Default.aspx.cs
"
Inherits
=
"
_Default
"
%>
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
<!
DOCTYPE html PUBLIC
"
-//W3C//DTD XHTML 1.1//EN
"
"
http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd
"
>
<
html xmlns
=
"
http://www.w3.org/1999/xhtml
"
>
<
head runat
=
"
server
"
>
<
title
>
Untitled Page
</
title
>
<
style type
=
"
text/css
"
>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
body
{ background-attachment:fixed;
background-image:url(Blue hills.jpg);
}
.style1
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
background-position:top center;
}
</
style
>
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
</
head
>
<
body onload
=
"
oSpan.className='style1'
"
>
<
form id
=
"
form1
"
runat
=
"
server
"
>
<
span style
=
"
font-size:14; width:250;
"
ID
=
"
oSpan
"
onmouseover
=
"
this.className='style2'
"
onmouseout
=
"
this.className='style1'
"
></
span
>
<
div
>
<
asp:ScriptManager ID
=
"
ScriptManager1
"
runat
=
"
server
"
>
</
asp:ScriptManager
>
</
div
>
<
asp:UpdatePanel ID
=
"
uid
"
runat
=
"
server
"
>
<
ContentTemplate
>
<
div
>
<
asp:Button ID
=
"
Button1
"
runat
=
"
server
"
Text
=
"
异步回送
"
OnClick
=
"
Button1_Click1
"
/>&
nbsp;
&
nbsp;
<
asp:Button ID
=
"
Button2
"
runat
=
"
server
"
Text
=
"
整页回送
"
OnClick
=
"
Button2_Click
"
/><
br
/>
<
asp:GridView ID
=
"
GridView1
"
runat
=
"
server
"
AutoGenerateColumns
=
"
False
"
Width
=
"
197px
"
>
<
Columns
>
<
asp:BoundField DataField
=
"
au_lname
"
FooterText
=
"
aaaa
"
HeaderText
=
"
au_lname
"
/>
</
Columns
>
</
asp:GridView
>
<
br
/>
<
asp:Label ID
=
"
Label1
"
runat
=
"
server
"
Text
=
"
当前时间
"
Font
-
Bold
=
"
True
"
Font
-
Size
=
"
Large
"
></
asp:Label
>
</
div
>
</
ContentTemplate
>
<
Triggers
>
<
asp:AsyncPostBackTrigger ControlID
=
"
Button1
"
/>
<
asp:PostBackTrigger ControlID
=
"
Button2
"
/>
</
Triggers
>
</
asp:UpdatePanel
>
<
div id
=
"
div1
"
>
&
nbsp;
</
div
>
</
form
>
</
body
>
</
html
>
UpdateMode:表示UpdatePanel的更新模式,有两个选项:Always和Conditional。Always是无论有没有Trigger,其它控件都将更新该UpdatePanel,Conditional表示仅仅有当前UpdatePanel的Trigger,或ChildrenAsTriggers属性为true时当前UpdatePanel中控件引发的异步回送或者整页回送,或是server端调用Update()方法才会引发更新该UpdatePanel。
Contente Template:用来定义UpdatePanel的内容
Triggers:分别为AsyncPostBackTrigger和PostBackTrigger
AsyncPostBackTrigge用来指定某个server端控件以及其将触发的server端事件作为该UpdatePanel的异步更新触发器,它须要设置的属性有控件ID和服务端控件的事件;PostBackTrigger用来指定在UpdatePanel中的某个服务端控件,它所引发的回送不使用异步回送,而仍然是传统的整页回送
如今我们来做一个简单的实例:
Contente Template:用来定义UpdatePanel的内容
Triggers:分别为AsyncPostBackTrigger和PostBackTrigger
AsyncPostBackTrigge用来指定某个server端控件以及其将触发的server端事件作为该UpdatePanel的异步更新触发器,它须要设置的属性有控件ID和服务端控件的事件;PostBackTrigger用来指定在UpdatePanel中的某个服务端控件,它所引发的回送不使用异步回送,而仍然是传统的整页回送
如今我们来做一个简单的实例:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
表示UpdatePanel终于呈现的HTML元素。Block(默认)表示<div>,Inline表示<span>
指定Button2实现整页更新。
.CS代码为:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
Button1实现一个数据集的异步更新,BUTTON2就是一般的赋值了。看看是不是非常easy呀!呵呵!