Sys.WebForms.PageLoadedEventArgs 类
更新:2007 年 11 月
由 Sys.WebForms.PageRequestManager 类的 pageLoaded 事件用于发送事件数据,这些数据表示在最近的回发中更新和创建的 UpdatePanel 控件。
命名空间:Sys.WebForms
var args = new Sys.WebForms.PageLoadedEventArgs();
构造函数
名称 |
说明 |
---|---|
初始化 PageLoadedEventArgs 类的新实例。 |
成员
名称 |
说明 |
---|---|
获取一个 JSON 数据结构,该数据结构包含使用 ScriptManager 类的 RegisterDataItem 方法注册的数据项。 |
|
获取 HTML <div> 元素的数组,这些元素表示在上次异步回发期间更新 DOM 时创建的 UpdatePanel 控件。 |
|
获取 HTML <div> 元素的数组,这些元素表示在上次回发期间更新 DOM 时更新的 UpdatePanel 控件。 |
说明: |
---|
此类包含支持客户端-脚本基础结构的私有成员,不能在代码中直接使用。私有成员的名称必须以下划线开头 ( _ )。 |
备注
UpdatePanel 控件呈现 HTML <div> 元素。pageLoaded 事件包含在页面上更新和创建的 <div> 元素的相关信息。panelsCreated 属性是因当前异步回发而创建的面板元素的数组。panelsUpdated 属性是因当前异步回发而更新的面板的数组。
示例
下面的示例演示如何使用 pageLoaded 事件提供在部分页更新期间对页面区域进行动画处理的脚本。事件数据 (args) 是 PageLoadedEventArgs 对象。
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub LinkButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
TextBox1.Text = DateTime.Now.ToString()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>PageRequestManager pageLoaded Event Example</title>
<style type="text/css">
body {
font-family: Tahoma;
}
.FieldSetStyle
{
width: 300px;
height: 100px;
}
.UpdatePanelContainer
{
width: 330px;
height:110px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<script type="text/javascript">
Type.registerNamespace("ScriptLibrary");
ScriptLibrary.BorderAnimation = function(color, duration) {
this._color = color;
this._duration = duration;
}
ScriptLibrary.BorderAnimation.prototype = {
animatePanel: function(panelElement) {
var s = panelElement.style;
s.borderWidth = '1px';
s.borderColor = this._color;
s.borderStyle = 'solid';
window.setTimeout(
function() {{ s.borderWidth = 0; }},
this._duration
);
}
}
ScriptLibrary.BorderAnimation.registerClass('ScriptLibrary.BorderAnimation', null);
var panelUpdatedAnimation = new ScriptLibrary.BorderAnimation('blue', 1000);
var postbackElement;
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded);
function beginRequest(sender, args) {
postbackElement = args.get_postBackElement();
}
function pageLoaded(sender, args) {
var updatedPanels = args.get_panelsUpdated();
if (typeof(postbackElement) === "undefined") {
return;
}
else if (postbackElement.id.toLowerCase().indexOf('external') > -1) {
for (i=0; i < updatedPanels.length; i++) {
panelUpdatedAnimation.animatePanel(updatedPanels[i]);
}
}
}
</script>
<p>
<asp:LinkButton ID="ExternalButton" runat="server" OnClick="LinkButton_Click">
Update the panel with animation.
</asp:LinkButton>
</p>
<hr />
<div class="UpdatePanelContainer">
<asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ExternalButton" />
</Triggers>
<ContentTemplate>
<fieldset id="FieldSet1" class="FieldSetStyle" runat="server">
<legend>UpdatePanel</legend>
<asp:TextBox runat="server" ID="TextBox1" />
<br />
<asp:LinkButton ID="InternalButton" runat="server" OnClick="LinkButton_Click">
Update the panel with no animation.
</asp:LinkButton>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void LinkButton_Click(object sender, EventArgs e)
{
TextBox1.Text = DateTime.Now.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>PageRequestManager pageLoaded Event Example</title>
<style type="text/css">
body {
font-family: Tahoma;
}
.FieldSetStyle
{
width: 300px;
height: 100px;
}
.UpdatePanelContainer
{
width: 330px;
height:110px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<script type="text/javascript">
Type.registerNamespace("ScriptLibrary");
ScriptLibrary.BorderAnimation = function(color, duration) {
this._color = color;
this._duration = duration;
}
ScriptLibrary.BorderAnimation.prototype = {
animatePanel: function(panelElement) {
var s = panelElement.style;
s.borderWidth = '1px';
s.borderColor = this._color;
s.borderStyle = 'solid';
window.setTimeout(
function() {{ s.borderWidth = 0; }},
this._duration
);
}
}
ScriptLibrary.BorderAnimation.registerClass('ScriptLibrary.BorderAnimation', null);
var panelUpdatedAnimation = new ScriptLibrary.BorderAnimation('blue', 1000);
var postbackElement;
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded);
function beginRequest(sender, args) {
postbackElement = args.get_postBackElement();
}
function pageLoaded(sender, args) {
var updatedPanels = args.get_panelsUpdated();
if (typeof(postbackElement) === "undefined") {
return;
}
else if (postbackElement.id.toLowerCase().indexOf('external') > -1) {
for (i=0; i < updatedPanels.length; i++) {
panelUpdatedAnimation.animatePanel(updatedPanels[i]);
}
}
}
</script>
<p>
<asp:LinkButton ID="ExternalButton" runat="server" OnClick="LinkButton_Click">
Update the panel with animation.
</asp:LinkButton>
</p>
<hr />
<div class="UpdatePanelContainer">
<asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ExternalButton" />
</Triggers>
<ContentTemplate>
<fieldset id="FieldSet1" class="FieldSetStyle" runat="server">
<legend>UpdatePanel</legend>
<asp:TextBox runat="server" ID="TextBox1" />
<br />
<asp:LinkButton ID="InternalButton" runat="server" OnClick="LinkButton_Click">
Update the panel with no animation.
</asp:LinkButton>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>