Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unit 02. ASP.NET Introduction HTML & Server controls Postbacks Page Lifecycle.

Similar presentations

Presentation on theme: "Unit 02. ASP.NET Introduction HTML & Server controls Postbacks Page Lifecycle."— Presentation transcript:

1 Unit 02. ASP.NET Introduction HTML & Server controls Postbacks Page Lifecycle

2 Creating an ASP.NET Project

3 Creating a ASP.NET Project File New Web Site… Web Site Location File System HTTP FTP Language VB.NET C#

4 ASP.NET Application Structure ASP.NET Folders App_Data App_Code App_LocalResources App_GlobalResources App_Browsers App_Themes Bin

5 ASP.NET Files Web Forms (.ASPX) and Code-behind files (.VB /.CS) Created in the root and subfolders of the site Classes & other shared code (.VB /.CS) Must go in the App_Code folder Global Application Class (Global.asax) Must go in the web root Web.config In the folder it applies to

6 Creating an ASPX page Web Site Add New Item… HTML / Design Views Controls can be dragged from the toolbox and initialised using the properties window

7 Page Elements HTML Tags Not interpreted by ASP.NET HTML Server Controls HTML Tags with RUNAT Attribute Can be manipulated using HtmlGenericControl Hello World

8 Page Elements Server Controls Expose specific methods and properties related to the control May be rendered as a single HTML tag, or set of tags Maintains its own state

9 Postback The page (including any controls on the page) stores it state in a hidden control within the form on the page When a form is submitted (by pressing a button) this information is posted back to the server The first request for a page is not a postback, but every subsequent request is

10 ASPX Page Object ASPX Request Life Cycle Incoming Request Control HTML HTML + State Outgoing Response HTML + State State

11 Adding code to the page Code can be added in two places Within the ASPX page In a separate (code-behind) file Location set when the page is created

12 Adding code to an ASPX Page Code is added in a script tag with a RUNAT="Server" attribute This is not ideal because the code and the design are mixed together Public _Message As String = Hello Sub SayHello() Response.Write(_Message) End Sub

13 Adding Code Behind A partial class is create to contain the code The partial class is compiled, with the ASPX page, to create the page class Page Object ASPX PageCode Behind +

14 Event Handling Code in an ASPX page is normally written in the form of event handlers Page Event handlers can be automatically "Wired up" Page_Load is used to initialise the page Protected Sub Page_Load() Me.Label1.Text = "Hello World End Sub VB

15 ASPX Page Life Cycle Init Load Unload Pre Render Load State Change Events Postback Event Save State

16 Control Events Change Events Occur before postback events Are triggered by a postback Can cause a postback if AutoPostback is set Postback Events There may be multiple change events, but there will only be one postback event

17 Add Control Event Handlers Control event handlers can be added with the properties window VB.NET uses the Handles notation C# uses control attributes (which can also be used in VB.NET) Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click VB

18 Lab Unit 2 Handling Control Events

Download ppt "Unit 02. ASP.NET Introduction HTML & Server controls Postbacks Page Lifecycle."

Similar presentations

Ads by Google