Agenda

Š ASP.NET Overview Š Programming Š Server Controls ASP.NET Overview

<%@ Page language="c#" %>

Programming Model Postbacks

Š A postback occurs when a page generates an HTML form whose values are sent back (via HTTP Post or Get) to the same page Š A common technique for handling form data Š In ASP and other server-side technologies the state of the page is lost upon postback... Š Unless you explicitly write code to maintain state Š This is tedious, bulky and error-prone Programming Model Postbacks Maintain State

Š By default, ASP.NET maintains the state of all server-side controls during a postback Š Can use method="post" or method="get" Š Server-side control objects are automatically populated during postback Š No state stored on server Š Works with all browsers Programming Model Code-behind pages

Š Two styles of creating ASP.NET pages

„ Controls and code in .aspx file

„ Controls in .aspx file, code in code-behind page z Supported in Visual Studio.NET Š Code-behind pages allow you to separate the user interface design from the code

„ Allows and designers to work independently

<%@ Codebehind=“WebForm1.cs” Inherits=WebApplication1.WebForm1” %> Programming Model Automatic Compilation

Š Just edit the code and hit the page Š ASP.NET will automatically compile the page into an assembly Š Compiled code is cached in the CLR Assembly Cache Š Subsequent page hits use compiled assembly Š If the text of the page changes then the code is recompiled

„ Works just like ASP: edit, save and run Programming Model Automatic Compilation Code- behind Parse Generate ASPX class Engine file

Request ASPX Instantiate ASPXFile Gen’d Request File Page Class File

Response Page Response Assembly Instantiate, process and render Agenda

Š ASP.NET Overview Š Programming Basics Š Server Controls Programming Basics Page Syntax

Š The most page is just static text

„ Any HTML page can be renamed .aspx Š Pages may contain:

„ Directives: <%@ Page Language=“C#” %>

„ Server controls:

„ Code blocks:

„ Data binding expressions: <%# %>

„ Server side comments: <%-- --%>

„ Render code: <%= %> and <% %> z Use is discouraged; use