INSPIRING CREATIVE AND INNOVATIVE MINDS Module 4: Adding Code to a Microsoft ASP.NET Web Form Implementing Code-Behind Pages Adding Event Procedures to.

Slides:



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

Module 8: Creating User Controls. Overview Adding User Controls to an ASP.NET Web Form Creating User Controls.
11 Getting Started with ASP.NET Beginning ASP.NET 4.0 in C# 2010 Chapters 5 and 6.
11 ASP.NET Slides based off:. 22 B ACKGROUND - W EB A RCHITECTURE Web Server PC/Mac/Unix/... + Browser Client Server Request:
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 1.1 of…
ASP.Net AJAX. AJAX Asynchronous JavaScript and XML: – JavaScript, Document Object Model, Cascade Style Sheet, XML, server-side script such as.Net, etc.
Web-Based Applications
Introduction to ASP.NET, Second Edition2 Chapter Objectives.
Performed by:Gidi Getter Svetlana Klinovsky Supervised by:Viktor Kulikov 08/03/2009.
Introduction to ASP.NET
Introduction to ASP.Net ISYS 350. ASP.NET ASP.NET is a server-side technology for creating dynamic web pages. ASP.NET allows you to use a selection of.
IT 533 Lecture Notes Gül ş en Demiröz Introduction to Web Programming using ASP.NET.
Web Forms. Agenda Web forms Web controls Code separation Dynamic compilation System.Web.UI.Page User controls.
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College Lecture 8: WebForms — Web-based.
ASP.Net, Web Forms and Web Controls 1 Outline Introduction Simple HTTP Transaction System Architecture Creating and Running a Simple Web Form Example Web.
Chapter 9 Web Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Visual Basic 2008 Express Edition The IDE. Visual Basic 2008 Express The Start Page Recent Projects Open an existing project Create a New Project.
Introduction to.Net and ASP.Net Course Introduction Build Your Own ASP.Net Website: Chapter 1 Microsoft ASP.Net Walkthrough: Creating a Basic Web Forms.
9-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
JavaScript & jQuery the missing manual Chapter 11
DR.JOHN ABRAHAM PROFESSOR UTPA ASP.NET. ACTIVE SERVER PAGES (ASP) Web application development environment Web applications use web browser to display.
Dr. Azeddine Chikh IS444: Modern tools for applications development.
HTML, GUI, ASP.NET Rina Zviel-Girshin Lecture 2
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
Beginning Web Site Development Module 1 – Dynamic Web Site Development Fundamentals of building dynamic Web sites with ASP.NET 2.0 and C# Version.
ASP.Net Web Applications. Characteristics of a typical data driven web application Web Server HTML Graphics Active-X Java Applets HTTP Request ADO / JDBC.
Web Application and Development Digital Media Department Unit Credit Value : 4 Essential Learning time : 120 hours Digital Media.
ASP Hello, world. ServerClient Response Request A form.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
© Minder Chen, ASP.NET 2.0: Introduction - 1 ASP.NET 2.0 Minder Chen, Ph.D. Framework Base Class Library ADO.NET: Data & XML.
IT 533 Lecture Notes Introduction to Web Programming using ASP.NET.
Developing Web Applications Using Microsoft ® Visual Studio ® 2008.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Programming with Visual Web Developer Chapter 9.
Internet Technologies and Web Application Web Services With ASP.NET Tutorial: Introduction to.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Unit 3: Adding Code to a Microsoft ASP.NET Web Form.
Module 4: Creating a Microsoft ASP.NET Web Form. Overview Creating Web Forms Using Server Controls.
Session 4: HTML and Web Server Controls. Outline Creating Web Forms Using Server Controls HTML Server Controls Web Server Controls Writing ASP Code Inline.
Module 1: Working with ASP.NET. Overview Introducing ASP.NET Creating Web Forms Adding ASP.NET Code to a Page Handling Page Events Discussion: ASP vs.
Module 3: Using Microsoft.NET- Based Languages. Overview Overview of the.NET-Based Languages Comparison of the.NET-Based Languages.
Christopher M. Pascucci.NET Programming CodeBehind.
Module 3 Designing and Developing a User Interface.
Christopher M. Pascucci.NET Programming: WebForm Events.
Module 4: Creating a Web Application with Web Forms
Module 4 Taking Control of the User Interface. Module Overview Sharing Logical Resources in an Application Creating Consistent User Interfaces by Using.
Web Application Development Introduction. Lesson: Creating Web Forms What is a Web Form? Creating a Web Form with Visual Studio.NET.
Asp.NET Core Server Controls. Slide 2 Lecture Overview Understanding the types of ASP.NET controls HTML controls ASP.NET (Web) controls.
1111 Creating ASPX Controls Programatically Objectives You will be able to Dynamically add controls to a page. Dynamically alter properties of controls.
Overview of Previous Lesson(s) Over View  ASP is a technology that enables scripts in web pages to be executed by an Internet server.  ASP.NET is a.
11 Getting Started with ASP.NET Beginning ASP.NET in C# and VB Chapters 1 and 2.
Module 1 Introducing C# and the.NET Framework. Module Overview Introduction to the.NET Framework 4 Creating Projects Within Visual Studio 2010 Writing.
Svetlin Nakov Telerik Corporation
PostBack  When an initial request for a page (a Web Form) is received by ASP.NET, it locates and loads the requested Web Form (and if necessary compiles.
11 User Controls Beginning ASP.NET in C# and VB Chapter 8.
 ASP.NET provides an event based programming model that simplifies web programming  All GUI applications are incomplete without enabling actions  These.
ASP.NET Part 2 Instructor: Charles Moen CSCI/CINF 4230.
ASP.NET Forms.
Session Variables and Post Back
Module 1: Getting Started
Introducing ASP.net with Visual Studio Environment
Module 10: Creating a Web Application with Web Forms
ASP.NET.
Web Development Using ASP .NET
Introduction to Web Programming using ASP.NET
ASP.NET 2.0 Overview Created By: Ajay Bahoriya.
GUI Programming in Visual Studio .NET
Presentation transcript:

INSPIRING CREATIVE AND INNOVATIVE MINDS Module 4: Adding Code to a Microsoft ASP.NET Web Form Implementing Code-Behind Pages Adding Event Procedures to Web Server Controls Handling Page Events

Lesson: Implementing Code-Behind Pages Methods for Implementing Code Writing Inline Code What Are Code-Behind Pages? How Code-Behind Pages Work

Methods for Implementing Code Three methods for adding code: –Put code in the same file as content (mixed) –Put code in a separate section of the content file (inline code) –Put code in a separate file (code-behind pages) Code-behind pages are the Visual Studio 2008 default

Writing Inline Code Code and content in the same file Different sections in the file for code and HTML [Visual C#] private void Button1_Click(object sender, System.EventArgs e) { } [Visual C#] private void Button1_Click(object sender, System.EventArgs e) { }

What Are Code-Behind Pages? Separation of code from content –Developers and UI designers can work independently Form1.aspxForm1.aspx Form1.aspx.cs Form1.aspx.cs or Form1.aspx.vb code code Separate filesSingle file

public partial class _Default : System.Web.UI.Page { private void Button1_Click() {... } public partial class _Default : System.Web.UI.Page { private void Button1_Click() {... } How Code-Behind Pages Work Create separate files for user interface and interface logic Page directive to link the two files –CodeFile –Inherits –AutoEventWireup Pre-compile or JIT-compile Default.aspxDefault.aspx.cs

Lesson: Adding Event Procedures to Web Server Controls What Are Event Procedures? Client-Side Event Procedures Server-Side Event Procedures Multimedia: Client-Side and Server-Side Events Creating Event Procedures Demonstration: Creating an Event Procedure Interacting with Controls in Event Procedures

What Are Event Procedures? Action in response to a user’s interaction with the controls on the page

Client-Side Event Procedures Internet Implement for only HTML controls Interpreted by the browser and run on the client No access to server resources Use Internet Client-side.HTM Pages

Server-Side Event Procedures Implement for both Web and HTML server controls Compiled and run on the server Access to server resources Use or Internet Server-side.ASPX Pages

Multimedia: Client-Side and Server-Side Events

Creating Event Procedures Visual Studio 2008 creates an event procedure template [Visual Basic] Private Sub Button1_Click(ByVal s As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click End Sub [Visual Basic] Private Sub Button1_Click(ByVal s As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click End Sub [Visual C#] private void Button1_Click(object s, System.EventArgs e) { } [Visual C#] private void Button1_Click(object s, System.EventArgs e) { } Note: Visual Basic uses the Handles keyword so that you can add many event procedures to one event

Demonstration: Creating an Event Procedure Create a Web Form by using Visual Studio 2008 Add controls to the Web Form Add a Click event procedure Browse the page

Notes Page Over-flow Slide. Do Not Print Slide. See Notes pane.

Interacting with Controls in Event Procedures Read the properties of Web server controls Output responses to other Web server controls [Visual C#] greetingString = "Hello " & nameTextBox.Text; [Visual C#] greetingString = "Hello " & nameTextBox.Text; [Visual Basic] greetingString = "Hello " + nameTextBox.Text; [Visual Basic] greetingString = "Hello " + nameTextBox.Text; [Visual C#] greetingLabel.Text = "new text"; [Visual C#] greetingLabel.Text = "new text"; [Visual Basic] greetingLabel.Text = "new text" [Visual Basic] greetingLabel.Text = "new text"

Lesson: Handling Page Events The Page Event Life Cycle Multimedia: The PostBack Process Demonstration: Handling Events Handling Page.IsPostback Events Linking Two Controls Together Demonstration: Linking Controls Together

The Page Event Life Cycle Control events Change Events Action Events Textbox1_Changed Page_PreInit Button1_Click Page_Load Page_PreLoad Page_Init Page_Unload Page is disposed

Multimedia: The PostBack Process

Demonstration: Handling Events View the page Change a check box to a Web server control Implement a Page.IsPostBack test

Notes Page Over-flow Slide. Do Not Print Slide. See Notes pane.

Handling Page.IsPostback Events Page_Load fires on every request –Use Page.IsPostBack to execute conditional logic –Page.IsPostBack prevents reloading for each postback [Visual Basic] Protected Sub Page_Load(ByVal s As System.Object, _ ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then End If End Sub [Visual Basic] Protected Sub Page_Load(ByVal s As System.Object, _ ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then End If End Sub [Visual C#] protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { } [Visual C#] protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { }

Linking Two Controls Together Linking one control to another is useful for taking values from list boxes or drop- down lists Data binding [Visual Basic] Protected Sub Page_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Me.Load selectedValueLabel.DataBind() End Sub [Visual Basic] Protected Sub Page_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Me.Load selectedValueLabel.DataBind() End Sub [Visual C#] protected void Page_Load(object sender, EventArgs e) { selectedValueLabel.DataBind(); } [Visual C#] protected void Page_Load(object sender, EventArgs e) { selectedValueLabel.DataBind(); } <asp:DropDownList id=“occupationList" autoPostBack="true" runat="server" > Program Manager Tester User Assistance You selected: <asp:Label id=“selectedValueLabel" Text=" " runat="server" /> <asp:DropDownList id=“occupationList" autoPostBack="true" runat="server" > Program Manager Tester User Assistance You selected: <asp:Label id=“selectedValueLabel" Text=" " runat="server" />

Demonstration: Linking Controls Together View the controls Link a Label to a ListBox control Bind data to the Label control Build and browse

Notes Page Over-flow Slide. Do Not Print Slide. See Notes pane.

Lab: Adding Functionality to a Web Application Exercise 1: Creating a Page_Load Event Procedure Exercise 2: Creating a Click Event Procedure Exercise 3: (If Time Permits): Implementing a Component in a User Control Logon information Virtual machine 2310C-LON-DEV-04 User name Student Password Pa$$w0rd Estimated time: 45 minutes

Lab Scenario Medical medical.aspx Benefits Home Page Default.aspx Life Insurance life.aspx Retirement retirement.aspx Dentists dental.aspx Doctors doctors.aspx Logon Page login.aspx Logon Page login.aspx Registration register.aspx Registration register.aspx Prospectus prospectus.aspx XML Web Service DentalService1.asmx Page Header header.ascx Lab Web Applicati on User Control nameDate.ascx Menu Component Benefits.cs or Benefits.vb Master Page benefitsMaster.master LINQ to SQL Classes Doctors.dbml ASPState Dentists Doctors XML Files Web. config TempDB

Lab Review Review Questions How can you run code only when a Web page loads for the first time? Where do the control event procedures occur in the page event life cycle? What is the default event procedure for common controls? How can you add items to a list in Design view?

Module Review and Takeaways Review Questions Real-World Issues and Scenarios Best Practices