大家好,又见面了,我是全栈君,祝每个程序员都可以多学几门语言。
重要的属性例如以下:
属性
|
说明
|
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。
|
Contente Template:用来定义UpdatePanel的内容
Triggers:分别为AsyncPostBackTrigger和PostBackTrigger
AsyncPostBackTrigge用来指定某个server端控件以及其将触发的server端事件作为该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
>
里面包括了一个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就是一般的赋值了。看看是不是非常easy呀!呵呵!
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/118219.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...