I create an asp.net page e.g. default.aspx.
I then define a button…
<asp:Button ID="btnNew" runat="server" Text="New" OnClick="btnNew_OnClick" />
… however I do not define the handler for btnNew_OnClick in code.
ASP.Net will tell me this when I start the page and throw an exception.
Therefore, does it use reflection to check if the class that implements my page has this method ?
Is this efficient if it has to do this each time it parses a page’s markup?
Not specifically. This happens when ASP.NET compiles your ASPX markup. ASPX markup is compiled the first time the page is hit on the fly, and stored somewhere in
C:\WINDOWS\Microsoft.NET\Framework\vX\Temporary ASP.NET Files.The exception to that is if you precompile your pages using
aspnet_compiler.exe. However, if you were to pre-compile it you’d see there error there, not when you hit the site.ASP.NET isn’t parsing the markup on every page view and post back; it’s only parsing it once when it’s compiled. It stored a hash of the page (usually called
hash.websomewhere in Temporary ASP.NET Files) and compares the hashes. If the hash is different (the page changed) then it recompiles it. Here is an example of what that compiled code may look like:This of course gets compiled into an executable assembly. Effectively, what the ASPX compiler is doing is compiling the server side markup into C# code, then compiler that into an assembly.