Understanding Code Behind
You might have noticed the Default.aspx.cs file in the PersonalPortal WebSites directory. You can also find the file underneath the Default.aspx page in Solution Explorer. This is the code behind file. In Chapter 3, when you created your first ASP.NET page, you learned how to designate code to be run on the server. This code was written inline with HTML, using the <script> tag or enclosed in <% and %>.
Adding code to your pages like this is fine when the code is simple and short. However, as code becomes longer and more complex, it can become difficult to maintain. Code behind is a way to separate code from markup to ease developing and maintaining complex code.
If you look at the code of Default.aspx in Example 4-1, it ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access