引发
Load 事件。
命名空间:System.Web.UI
程序集:System.Web(在 system.web.dll 中)
Protected Friend Overridable Sub OnLoad ( _
e As EventArgs _
)
Dim e As EventArgs
Me.OnLoad(e)
protected internal virtual void OnLoad (
EventArgs e
)
protected public:
virtual void OnLoad (
EventArgs^ e
)
protected void OnLoad (
EventArgs e
)
protected internal function OnLoad (
e : EventArgs
)
参数
- e
包含事件数据的 EventArgs 对象。
此方法通知服务器控件应执行关联页的每个 HTTP 请求的共同操作,例如设置数据库查询。在页生存期的此阶段,创建并初始化层次结构中的服务器控件,还原视图状态,并且窗体控件反映客户端数据。
使用 IsPostBack 属性确定该页是否正为响应客户端回发而加载,或者它是否正被首次加载和访问。
下面的示例创建一个文本流对象 myFile;如果在处理请求期间发生定义的 Page 和控件生命周期事件,则使用该对象将消息输出到文本文件。在调用 OnLoad 方法期间,字符串 "Custom control has loaded" 将写入文件,并文本流对象将关闭。
' Create a StreamWriter to write data to a text file.
Dim myFile As TextWriter = File.CreateText("c:\NewTextFile.txt")
Sub Page_Load(sender As Object, e As EventArgs)
' Write status to file.
myFile.WriteLine("Page has loaded.")
End Sub
Sub CustomControl_OnLoad(sender As Object, e As EventArgs)
myFile.WriteLine("Custom control has loaded.")
End Sub
Sub CustomControl_OnUnload(sender As Object, e As EventArgs)
' Server controls final cleanup such as;
' closing files etc.goes here
myFile.WriteLine("Custom control was unloaded.")
' Close the stream object.
myFile.Close()
End Sub
// Create a StreamWriter to write data to a text file.
TextWriter myFile = File.CreateText("c:\\NewTextFile.txt");
void Page_Load(object sender,EventArgs e)
{
// Write status to file.
myFile.WriteLine("Page has loaded.");
}
void CustomControl_OnLoad(object sender,EventArgs e)
{
myFile.WriteLine("Custom control has loaded.");
}
void CustomControl_OnUnload(object sender,EventArgs e)
{
// Server controls final cleanup such as;
// closing files goes here
myFile.WriteLine("Custom control was unloaded.");
// Close the stream object.
myFile.Close();
}
// Create a StreamWriter to write data to a text file.
TextWriter myFile = File.CreateText("c:\\NewTextFile.txt");
void Page_Load(Object sender,EventArgs e)
{
// Write status to file.
myFile.WriteLine("Page has loaded.");
} //Page_Load
void CustomControl_OnLoad(Object sender,EventArgs e)
{
myFile.WriteLine("Custom control has loaded.");
} //CustomControl_OnLoad
void CustomControl_OnUnload(Object sender,EventArgs e)
{
// Server controls final cleanup such as;
// closing files goes here
myFile.WriteLine("Custom control was unloaded.");
// Close the stream object.
myFile.Close();
} //CustomControl_OnUnload
Windows 98、Windows 2000 SP4、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
.NET Framework
受以下版本支持:2.0、1.1、1.0