E
Eddie Chan
Dear Sir,
I have a question on the order of event called during using a custom
control when in
1. not IsPostBack and 2. IsPostBack situation
I have an aspx file with the following code.
<%@ Page Language="C#" CodePage="65001" Debug="true"
autoeventwireup="True" %>
<%@ Register TagPrefix="GeneralDataGrid" Namespace="GeneralDataGrid "
Assembly="GeneralDataGrid" %>
<%@ import Namespace="System.Collections" %>
<%@ Import Namespace="System.Data" %>
<script runat="server">
void Page_Init() {
Response.Write("Start of Page Init<br>");
Response.Write("End of Page Init<br>");
}
void Page_Load(Object sender, EventArgs e) {
Response.Write("Start of Page Load<br>");
Response.Write("End of Page Load<br>");
}
void Page_PreRender() {
Response.Write("Start of Page PreRender<br>");
Response.Write("End of Page PreRender<br>");
}
</script>
<html>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"
bgcolor="#FFFFFF">
<form runat="server">
<GeneralDataGrid:CompositeDataGrid id="xxx" runat="server"/>
<hr/>
<p>
<asp:Button id="btn" runat="server" Text="ginger"/>
</form>
</body>
</html>
and the following are the C# code for the custom control.
// GeneralDataGrid.cs
using System;
namespace GeneralDataGrid {
public class CompositeDataGrid : Control, INamingContainer {
protected override void CreateChildControls() {
Context.Response.Write("Start of CreateChildControls<br>");
Context.Response.Write("End of CreateChildControls<br>");
}
protected override void OnLoad(EventArgs e) {
Context.Response.Write("Start of OnLoad<br>");
//------------------------------------------------
// BLOCK A - Control "fsdkf;sk;flk" does not exist!
//------------------------------------------------
Control xxx = FindControl("fsdkf;sk;flk");
//------------------------------------------------
// END OF BLOCK A
//------------------------------------------------
Context.Response.Write("End of OnLoad<br>");
}
protected override void OnInit(EventArgs e) {
Context.Response.Write("Start of OnInit<br>");
Context.Response.Write("End of OnInit<br>");
}
protected override void OnPreRender(EventArgs e) {
Context.Response.Write("Start of OnPreRender<br>");
Context.Response.Write("End of OnPreRender<br>");
}
}
}
What I want to ask is if the line within BLOCK A is NOT remarked, then
the result is as this
(Not IsPostBack state)
Start of OnInit
End of OnInit
Start of Page Init
End of Page Init
Start of Page Load
End of Page Load
Start of OnLoad
Start of CreateChildControls
End of CreateChildControls
End of OnLoad
Start of Page PreRender
End of Page PreRender
Start of OnPreRender
End of OnPreRender
You can see that CreateChildControls is called within OnLoad
However, when I remark the the line between BLOCK A, the result is as
follows.
(Not IsPostBack state)
Start of OnInit
End of OnInit
Start of Page Init
End of Page Init
Start of Page Load
End of Page Load
Start of OnLoad
End of OnLoad
Start of Page PreRender
End of Page PreRender
Start of CreateChildControls
End of CreateChildControls
Start of OnPreRender
End of OnPreRender
which CreateChildControls is called after Page_PreRender
Why does it happen? Can somebody help?
Eddie Chan
I have a question on the order of event called during using a custom
control when in
1. not IsPostBack and 2. IsPostBack situation
I have an aspx file with the following code.
<%@ Page Language="C#" CodePage="65001" Debug="true"
autoeventwireup="True" %>
<%@ Register TagPrefix="GeneralDataGrid" Namespace="GeneralDataGrid "
Assembly="GeneralDataGrid" %>
<%@ import Namespace="System.Collections" %>
<%@ Import Namespace="System.Data" %>
<script runat="server">
void Page_Init() {
Response.Write("Start of Page Init<br>");
Response.Write("End of Page Init<br>");
}
void Page_Load(Object sender, EventArgs e) {
Response.Write("Start of Page Load<br>");
Response.Write("End of Page Load<br>");
}
void Page_PreRender() {
Response.Write("Start of Page PreRender<br>");
Response.Write("End of Page PreRender<br>");
}
</script>
<html>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"
bgcolor="#FFFFFF">
<form runat="server">
<GeneralDataGrid:CompositeDataGrid id="xxx" runat="server"/>
<hr/>
<p>
<asp:Button id="btn" runat="server" Text="ginger"/>
</form>
</body>
</html>
and the following are the C# code for the custom control.
// GeneralDataGrid.cs
using System;
namespace GeneralDataGrid {
public class CompositeDataGrid : Control, INamingContainer {
protected override void CreateChildControls() {
Context.Response.Write("Start of CreateChildControls<br>");
Context.Response.Write("End of CreateChildControls<br>");
}
protected override void OnLoad(EventArgs e) {
Context.Response.Write("Start of OnLoad<br>");
//------------------------------------------------
// BLOCK A - Control "fsdkf;sk;flk" does not exist!
//------------------------------------------------
Control xxx = FindControl("fsdkf;sk;flk");
//------------------------------------------------
// END OF BLOCK A
//------------------------------------------------
Context.Response.Write("End of OnLoad<br>");
}
protected override void OnInit(EventArgs e) {
Context.Response.Write("Start of OnInit<br>");
Context.Response.Write("End of OnInit<br>");
}
protected override void OnPreRender(EventArgs e) {
Context.Response.Write("Start of OnPreRender<br>");
Context.Response.Write("End of OnPreRender<br>");
}
}
}
What I want to ask is if the line within BLOCK A is NOT remarked, then
the result is as this
(Not IsPostBack state)
Start of OnInit
End of OnInit
Start of Page Init
End of Page Init
Start of Page Load
End of Page Load
Start of OnLoad
Start of CreateChildControls
End of CreateChildControls
End of OnLoad
Start of Page PreRender
End of Page PreRender
Start of OnPreRender
End of OnPreRender
You can see that CreateChildControls is called within OnLoad
However, when I remark the the line between BLOCK A, the result is as
follows.
(Not IsPostBack state)
Start of OnInit
End of OnInit
Start of Page Init
End of Page Init
Start of Page Load
End of Page Load
Start of OnLoad
End of OnLoad
Start of Page PreRender
End of Page PreRender
Start of CreateChildControls
End of CreateChildControls
Start of OnPreRender
End of OnPreRender
which CreateChildControls is called after Page_PreRender
Why does it happen? Can somebody help?
Eddie Chan