专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »Asp教程 » updatepanel:UpdatePanel的简单用法 »正文

updatepanel:UpdatePanel的简单用法

来源: 发布时间:星期四, 2009年2月12日 浏览:118次 评论:0


PageRequestManager-pageLoading事件(客户端已经获得服务器结果但是还没有对页面进行设置时触发)

参数类型:PageLoadingEventArgs
dataItems属性: 获得服务器端注册数据项
panelsDeleting属性: 获得即将删除UpdatePanel
panelsUpdating属性:获得即将更新UpdatePanel

注意:如果updatePanel是恰套使用
外部updatePanel刷新时候里面updatePanel会先删除内部updatePanel然后再创建
此时会有panelsDeleting属性


常见操作:
提示更新updatepanel
获得服务服务器端注册数据项


PageRequestManager-pageLoading事件例子显示更新 updatePanel



为了简化代码:用了个简单用户Control控件
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="AJAXEnabledWebApplication1.WebUserControl1" %>

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<%=DateTime.Now. %>
</ContentTemplate>
</asp:UpdatePanel>


cs 代码:
using ;
using .Collections;
using .Configuration;
using .Data;
using .Web;
using .Web.Security;
using .Web.UI;
using .Web.UI.HtmlControls;
using .Web.UI.WebControls;
using .Web.UI.WebControls.WebParts;

AJAXEnabledWebApplication1
{
public partial WebUserControl1 : .Web.UI.UserControl
{
public Random random = Random(DateTime.Now.Millisecond);
protected void Page_Load(object sender, EventArgs e)
{
(random.NextDouble > 0.5)
{
this.UpdatePanel1.Update;
}
}
}
}
页面代码:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm6.aspx.cs" Inherits="AJAXEnabledWebApplication1.WebForm6" %>

<%@ Register src="WebUserControl1.ascx" tagname="WebUserControl1" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<br />
<uc1:WebUserControl1 ID="WebUserControl11" runat="server" />
<br />
<uc1:WebUserControl1 ID="WebUserControl12" runat="server" />
<br />
<uc1:WebUserControl1 ID="WebUserControl13" runat="server" />
<br />
<uc1:WebUserControl1 ID="WebUserControl14" runat="server" />
<br />
<uc1:WebUserControl1 ID="WebUserControl15" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Button" />
<script type="text/javascript" language="javascript">
function hightLightPanels(panels,clear){
for(var i=0;i<panels.length;i){
var panel=panels[i];
panel.style.border=clear?"solid 0px white":"solid 1px red";
panel.style.backgroundcolor=clear?"white":"#34ff44";
}
}

Sys.WebForms.PageRequestManager.getInstance.add_pageLoading(
function(sender, e){
//e.get_panelsUpdating 获得需要更新panels
//Array.clone份copy
var panelsUpdating=Array.clone(e.get_panelsUpdating);
hightLightPanels(panelsUpdating);
window.Timeout(
function{
hightLightPanels(panelsUpdating,true);
},2000
);
}
);
</script>
</form>
</body>
</html>


cs代码:
using ;
using .Collections;
using .Configuration;
using .Data;
using .Web;
using .Web.Security;
using .Web.UI;
using .Web.UI.HtmlControls;
using .Web.UI.WebControls;
using .Web.UI.WebControls.WebParts;

AJAXEnabledWebApplication1
{
public partial WebForm6 : .Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//注册button为异步更新Control控件
ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(this.Button1);
}
}
}

就这么多了
0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: