Search code examples
asp.netpage-lifecycle

Server-Side-Code in aspx file


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???


Solution

  • 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.