UpdatePanel控件也是Ajax里用得最多的控件之一,UpdatePanel控件是用来局部更新网页上的内容,网页上要局部更新的内容必须放在UpdatePanel控件里,他必须和上一次说的ScriptManager控件一起使用。现在来看UpdatePanel的属性
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中控件引发的异步回送或者整页回送,或是服务器端调用Update()方法才会引发更新该UpdatePanel。
|
ChildrenAsTriggers:当UpdateMode属性为Conditional时,UpdatePanel中的子控件的异步回送是否会引发UpdatePanle的更新。
RenderMode:表示UpdatePanel最终呈现的HTML元素。Block(默认)表示<div>,Inline表示<span>
<%
@ Page Language
=
“
C#
“
AutoEventWireup
=
“
true
“
CodeFile
=
“
Default.aspx.cs
“
Inherits
=
“
_Default
“
%>
<!
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
“
>
body
{ background–attachment:fixed;
background–image:url(Blue hills.jpg);
}
.style1
{
background–position:top center;
}
</
style
>
</
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中控件引发的异步回送或者整页回送,或是服务器端调用Update()方法才会引发更新该UpdatePanel。
Contente Template:用来定义UpdatePanel的内容
Triggers:分别为AsyncPostBackTrigger和PostBackTrigger
AsyncPostBackTrigge用来指定某个服务器端控件以及其将触发的服务器端事件作为该UpdatePanel的异步更新触发器,它需要设置的属性有控件ID和服务端控件的事件;PostBackTrigger用来指定在UpdatePanel中的某个服务端控件,它所引发的回送不使用异步回送,而仍然是传统的整页回送
现在我们来做一个简单的实例:
Contente Template:用来定义UpdatePanel的内容
Triggers:分别为AsyncPostBackTrigger和PostBackTrigger
AsyncPostBackTrigge用来指定某个服务器端控件以及其将触发的服务器端事件作为该UpdatePanel的异步更新触发器,它需要设置的属性有控件ID和服务端控件的事件;PostBackTrigger用来指定在UpdatePanel中的某个服务端控件,它所引发的回送不使用异步回送,而仍然是传统的整页回送
现在我们来做一个简单的实例:
<%
@ Page Language
=
“
C#
“
AutoEventWireup
=
“
true
“
CodeFile
=
“
Default.aspx.cs
“
Inherits
=
“
_Default
“
%>
<!
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
“
>
body
{ background–attachment:fixed;
background–image:url(Blue hills.jpg);
}
.style1
{
background–position:top center;
}
</
style
>
</
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
>
表示UpdatePanel最终呈现的HTML元素。Block(默认)表示<div>,Inline表示<span>
里面包含了一个Triggers,里面第一个属性
AsyncPostBackTrigger指定Button1实现异步更新,而PostBackTrigger
指定Button2实现整页更新。
.CS代码为:
protected
void
Button1_Click1(
object
sender, EventArgs e)
{
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)
{
this.Label1.Text = “11111“;
}
Button1实现一个数据集的异步更新,BUTTON2就是一般的赋值了。看看是不是很简单呀!呵呵! 今天的文章update table_update嵌套select语句「建议收藏」分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/74987.html