E-Commerce: Introduction to ASP.Net Application Architecture 1 Dr. Lawrence West, Management Dept., University of Central Florida Topics.

Slides:



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

HTML Forms. collect information for passing to server- side processes built up from standard widgets –text-input, radio buttons, check boxes, option lists,
23-Aug-14 HTML/XHTML Forms. 2 What are forms? is just another kind of XHTML/HTML tag Forms are used to create (rather primitive) GUIs on Web pages Usually.
Lecture 6/2/12. Forms and PHP The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input When dealing with HTML forms.
Introduction to ASP.NET, Second Edition2 Chapter Objectives.
Promoting Code Reuse Often in programming, multiple procedures will perform the same operation IN OTHER WORDS – the same piece of code will do the same.
CS0004: Introduction to Programming Events. Review  Event Procedure  A set of instructions to be executed when a certain event happens.  Many event-driven.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
DR.JOHN ABRAHAM PROFESSOR UTPA ASP.NET. ACTIVE SERVER PAGES (ASP) Web application development environment Web applications use web browser to display.
Chapter 3 Using Validation Controls. What is a Validation Control? A control that validates the value in another control Renders as an HTML tag with an.
Dr. Azeddine Chikh IS444: Modern tools for applications development.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College
IMS 4212: Application Architecture and Intro to Stored Procedures 1 Dr. Lawrence West, Management Dept., University of Central Florida
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
Christopher M. Pascucci.NET Programming: Forms & Controls.
INSPIRING CREATIVE AND INNOVATIVE MINDS Module 4: Adding Code to a Microsoft ASP.NET Web Form Implementing Code-Behind Pages Adding Event Procedures to.
E-Commerce: Introduction to Web Development 1 Dr. Lawrence West, Management Dept., University of Central Florida Topics What is a Web.
© Minder Chen, ASP.NET 2.0: Introduction - 1 ASP.NET 2.0 Minder Chen, Ph.D. Framework Base Class Library ADO.NET: Data & XML.
CSCI 6962: Server-side Design and Programming Introduction to Active Server Pages.
ASP.NET.. ASP.NET Environment ASP.NET is Microsoft's programming framework that enables the development of Web applications and services. It is an easy.
Chapter 8 Collecting Data with Forms. Chapter 8 Lessons Introduction 1.Plan and create a form 2.Edit and format a form 3.Work with form objects 4.Test.
Introduction to ASP.NET1. 2 Web applications in general Web applications are divided into two parts –The server part –The client part The server part.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Unit 3: Adding Code to a Microsoft ASP.NET Web Form.
Christopher M. Pascucci Basic Structural Concepts of.NET Managing State & Scope.
IMS 3253: Subroutines 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Procedures Subroutines Parameters –By Value.
Module 4: Creating a Microsoft ASP.NET Web Form. Overview Creating Web Forms Using Server Controls.
ASP.NET 4 Unleashed Chapter 1. .aspx page: contains C# script and HTML code including tags. Listing 1.1 FirstPage.aspx.
IMS 4480: Introduction to Web Services 1 Dr. Lawrence West, MIS Dept., University of Central Florida Introduction to Web Services—Topics.
Copyright © Texas Education Agency, All rights reserved.1 Web Technologies Website Forms / Data Acquisition.
1 HTML forms (cont.)
MIS 3200 – Unit 3.2 Page_Load method AutoPostBack property of controls IsPostBack method of the Page object Understanding web page life cycle.
HTML Forms. A form is simply an area that can contain form fields. Form fields are objects that allow the visitor to enter information - for example text.
Creating Menus Menu Bar – behaves like standard Windows menus Can be used in place of or in addition to buttons to execute a procedure Menu items are controls.
CIS 375—Web App Dev II ASP.NET 5 Events. 2 The Page_Load Event The Page_Load event is triggered when a page loads. [Example]Example Sub Page_Load lbl1.Text="The.
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.
IMS 3253: Controls 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Check Boxes Radio Buttons Date Time Picker Masked.
IMS 4212: Application Architecture and Intro to Stored Procedures 1 Dr. Lawrence West, Management Dept., University of Central Florida
IMS 3253: Forms, Controls, Properties, Events 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Program Elements Assignment.
IMS 4212: Constraints & Triggers 1 Dr. Lawrence West, Management Dept., University of Central Florida Stored Procedures in SQL Server.
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.
IMS 3253: Validation and Errors 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Validation and Error Handling Validation.
Beginning ASP.NET in C# and VB Chapter 9
Visual Basic.NET BASICS Lesson 9 Nested If Statements and Radio Buttons.
HTML Structure II (Form) WEEK 2.2. Contents Table Form.
FORMS Explained By: Jasdeep Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
COMPUTER PROGRAMMING I Apply Procedures to Develop List Box and Combo Box Objects.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Creating an Interactive Web Page Lesson 2. Objectives.
Teaching slides Chapter 6. Chapter 6 Software user interface design & construction Contents Introduction Graphical user interface – Rich window based.
2440: 141 Web Site Administration Web Forms Instructor: Joseph Nattey.
Creating and Processing Web Forms
ASP.NET Forms.
Working with ASP.NET Server Controls
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Objectives Design a form Create a form Create text fields
Introduction to Triggers
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Unit 27 - Web Server Scripting
Visual Basic.
Multi-Form Applications Things You Need to Know
Module 05: Building ASP .NET Applications
Web Development Using ASP .NET
5/6/2019 Session 8.2 Postback, ViewState
Presentation transcript:

e-Commerce: Introduction to ASP.Net Application Architecture 1 Dr. Lawrence West, Management Dept., University of Central Florida Topics Introduction to Forms and their Contents Event Code Code-Behind Processing Forms—The Required Round Trip The Viewstate Processing Forms—Breaking Free The Page_Load Event

e-Commerce: Introduction to ASP.Net Application Architecture 2 Dr. Lawrence West, Management Dept., University of Central Florida Forms and their Contents Every.ASPX page contains one and only one form Forms are objects that support events Forms contain subordinate objects –Most important is the collection of controls –May have other containers that may also contain controls (more later) –Controls also support events and have properties

e-Commerce: Introduction to ASP.Net Application Architecture 3 Dr. Lawrence West, Management Dept., University of Central Florida Forms and their Contents (cont.) Certain actions on the displayed form cause the form and its controls to be posted back to the server –Pushing any button on the form –Setting the Autopostback property of a control to True (default is False) At the server, code in the relevant events executes –Page_Load event always executes (if present) –Other controls have event code that execute if the event occurred since the last page submission –We will look at events as we look at controls

e-Commerce: Introduction to ASP.Net Application Architecture 4 Dr. Lawrence West, Management Dept., University of Central Florida Event Code Many objects, especially controls, have events for which code can be written Fewer events than in Windows versions Common Events include –Page (or form): Page_Load –Button: _Click –Lists: _SelectedIndexChanged –Text Box: _TextChanged Private Sub cmdSubtract_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles cmdSubtract.Click lblAnswer.Text = (CSng(txtFirstNum.Text) _ - CSng(txtSecondNum.Text)).ToString End Sub

e-Commerce: Introduction to ASP.Net Application Architecture 5 Dr. Lawrence West, Management Dept., University of Central Florida Event Code (Cont.) It is common for the same form posting to execute multiple events It is sometimes important to know the order in which the events execute –You will need to experiment when this is the case –How would you do this? Only one button _Click event should ever execute

e-Commerce: Introduction to ASP.Net Application Architecture 6 Dr. Lawrence West, Management Dept., University of Central Florida Code Behind There are two possible places to put your event code –Procedures at the top of your HTML view of the page Illustrated in the majority of ASP.Net books available on the market –“Code Behind” page associated with your form Approach in our text We will always use Code Behind –Sharable –Uses same VB environment –Better editor support

e-Commerce: Introduction to ASP.Net Application Architecture 7 Dr. Lawrence West, Management Dept., University of Central Florida The Form Round Trip When a form is submitted, it posts back to itself –Code associated with the form handles all events triggered by the form and its controls –Unless directed otherwise, the form redisplays itself –This programming model defaults to keeping application on one form But most applications require a sequence of forms What are the advantages of this approach? How do we break free (move to different forms)? Classic ASP and ASP.Net 2.0 do allow forms to post to a different page (form)

e-Commerce: Introduction to ASP.Net Application Architecture 8 Dr. Lawrence West, Management Dept., University of Central Florida The Form Round Trip—Staying on the Same Page Some applications require recursive use of one page –Repeatedly adding products to a shopping cart –Registering for multiple classes Many, many applications require validation of some step before moving to the next step (form) –Failed validation needs display of the same information along with information on the problem to be corrected –Major advantage of the round trip model

e-Commerce: Introduction to ASP.Net Application Architecture 9 Dr. Lawrence West, Management Dept., University of Central Florida The Form Round Trip—Staying on the Same Page (Cont.) Form flexibility –It is possible to make one form behave like many by putting controls in panels –Panels can be selectively turned visible or invisible depending on progress through the application –A single form, therefore, can look like a series of forms executing a sequential transaction –Code can be easily used throughout the form But same thing can be used with independent classes (classes not tied to a form)

e-Commerce: Introduction to ASP.Net Application Architecture 10 Dr. Lawrence West, Management Dept., University of Central Florida The Viewstate Viewstate is a special hidden control on a form that records the state of the form when it was last sent to the browser Hidden controls are controls that are just what you’d think they are –They contain values –Are submitted to the server with the form –Are not visible to the user –Hidden controls can be seen in the View Source menu from the browser

e-Commerce: Introduction to ASP.Net Application Architecture 11 Dr. Lawrence West, Management Dept., University of Central Florida The Viewstate (Cont.) Viewstate values are encoded (but not encrypted) Viewstates can be encrypted (we will not cover) Viewstate changes with contents of the form –Viewstate on our form when it first loads –Viewstate when a different color is selected and different numbers entered in the text boxes <input type="hidden" name="__VIEWSTATE" value="dDwtMTE4NjMwMjUyNTs7Pp07RgJob7AmWNf0ELcqIroUfgAO" /> <input type="hidden" name="__VIEWSTATE" value="dDwtMTE4NjMwMjUyNTt0PDtsPGk8MT47PjtsPHQ8O2w8aTwxPjtpPD M+Oz47bDx0PDtsPGk8Mz47PjtsPHQ8cDxwPGw8VGV4dDs+O2w8Qmx1ZTs+Pj s+Ozs+Oz4+O3Q8O2w8aTw1Pjs+O2w8dDxwPHA8bDxUZXh0Oz47bDwxNTs+Pj s+Ozs+Oz4+Oz4+Oz4+Oz4zrwEswgAzGgO08kaDxfYLD3Tr+w==" />

e-Commerce: Introduction to ASP.Net Application Architecture 12 Dr. Lawrence West, Management Dept., University of Central Florida The Viewstate (Cont.) Viewstate can lead to efficiencies Controls automatically retain their contents unless changed by the user or explicitly changed in code –Old ASP required controls to be explicitly set or they defaulted to their design values Trips to the database can be avoided –If DB values are unlikely to have changed controls can be loaded from the DB on the first load –Subsequent displays can be loaded from the viewstate

e-Commerce: Introduction to ASP.Net Application Architecture 13 Dr. Lawrence West, Management Dept., University of Central Florida The Viewstate (cont.) Sometimes viewstate gets in the way –If real-time database values are required for every page load the old values are still retained in viewstate –Viewstate for large amounts of data can take up as much space as the data itself Viewstate for individual controls can be disabled by setting the EnableViewState property to False –True is the default value

e-Commerce: Introduction to ASP.Net Application Architecture 14 Dr. Lawrence West, Management Dept., University of Central Florida Processing Forms—Breaking Free Execution can be branched to another form using a variety of techniques Most common is the Response.Redirect option –Response.Redirect(“TargetUrl”) –Response.Redirect(“WebForm2.aspx”) –“Response” is an intrinsic (built in, always available) object that reflects the stream of output being sent to the browser –.Redirect changes the page that provides the response to the specified URL –Response.Redirect does not carry any values forward

e-Commerce: Introduction to ASP.Net Application Architecture 15 Dr. Lawrence West, Management Dept., University of Central Florida The Page Load Event & IsPostBack The Page_Load event is automatically provided with every code behind form page (but may be erased) The Me.IsPostBack logical property can be used to tell if … –False: Page is being loaded (for the first time) based on an external call –True: Page is being loaded because the form was posted back to itself Especially useful to determine when controls must be loaded by a database call

e-Commerce: Introduction to ASP.Net Application Architecture 16 Dr. Lawrence West, Management Dept., University of Central Florida The Page Load Event & IsPostBack (cont.) Private Sub Page_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load '************************************************************ '* Tests to see if the page is posting back and sets a label '* value depending on the status '************************************************************ If Me.IsPostBack Then lblIsPostBack.Text = " has posted back." Else lblIsPostBack.Text = " has not posted back." End If End Sub If Not Me.IsPostBack Then Common test for initial page load