views:

307

answers:

3

I wonder what is processed first: if the code placed in the aspx part (using server tags <% %>) or the code behind, because I place a variable that is filled in the Page_Load in the aspx between server tags and I'm not getting anything when there is a value.

Anyone can point me in some directions like an article talking about the page lifecycle that includes the aspx code?

Thanks!

+2  A: 

From MSDN: ASP.NET Page Life Cycle Overview

(http://msdn.microsoft.com/en-us/library/ms178472.aspx)

CD
that link is busted, try this: http://msdn.microsoft.com/en-us/library/ms178472.aspx
blesh
Link is http://msdn.microsoft.com/en-us/library/ms178472.aspx
veggerby
+1  A: 

As the other poster says, there's a documented lifecycle.

That aside, the codebehind represents the base class, the aspx the derived class. The markup in the ASPX is actually compiled into native code, so the true answer is that the page and the codebehind are essentially one instance, since the compiled ASPX inherits the Page-derived code in the codebehind.

-Oisin

x0n
The inheritance is no longer true. The ASPX is one part of a partial class declaration and the behind file is another part of the _same_ partial class.
Rune FS
Ah, never noticed. Still, the effect is the same.
x0n
+1  A: 

When HttpHandler calls ProcessRequest() method, it starts with creating a Autogenerated class from .aspx file. This autogenerated class will create page's control hierarchy for .aspx page which is just converting declarative syntax into actual code in C# or VB. This autogenerated class is then combined with partial code behind class. Now this completed class will serve as base class to .aspx page. This class is stored inside \WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files. And this class will server all the request for the page. So if you have any Protected/public variable declared inside partial code behind class and you populate that variable with some value in Page_load, and if you wants to print on .aspx page using <%=variablename %>, it should print the value which is assigned in Page_Load on web page.

Neil
Very useful, thank you!
Sebastian