3

I want to ask in which phase of Control Execution Lifecycle is the "Server-Side-Code written in aspx file" being executed?

Is it before SaveState or after, I claim it's in the rendering phase, is it true??

in aspx file if my code writen as

"<%"

if(true)
{
rdlistAnswers.Items.Clear();
foreach (string item in myCollection)
{
    i.Value = item;
    i.Text = item;
    rdlistAnswers.Items.Add(i);
}
"%>"
<asp:RadioButtonList ID="rdlistAnswers" runat="server"</asp:RadioButtonList>

the changes made to the are rendered but not saved. but when write the tag as

<asp:RadioButtonList ID="rdlistAnswers" runat="server" OnPreRender="loadMe"</asp:RadioButtonList>

-as loadMe is an event handler method in the aspx.cs file makes the same thing as code above- the changes are rendered and saved, so when I do changes in PreRender phase the state is saved but when I do it by placing the logic in the aspx file its not saved, this means -at least as I claim- that server-side code placed in aspx file executes in rendering phase, do you agree me???

netseng
  • 2,226
  • 6
  • 24
  • 28

1 Answers1

5

Code written directly inside the aspx file will be executed at the end of Render Control in the ASP.NET page lifecycle.

I tested it precompiling an aspx file and using Reflector to look at the decompiled code.

Community
  • 1
  • 1
splattne
  • 102,760
  • 52
  • 202
  • 249
  • Ok, I noticed that when I'm tracing my code, but for POC I'm serching for an article explains code execution cycle in asp.net, didn't you saw one?? – netseng Jan 06 '09 at 12:04
  • Well, there is the MSDN article: http://msdn.microsoft.com/en-us/library/ms178472.aspx and Best Practices here: http://www.aspfree.com/c/a/ASP.NET/ASP.NET-Life-Cycle-and-Best-Practices/ and another one here: http://www.15seconds.com/issue/020102.htm – splattne Jan 06 '09 at 13:45