Event Handling & Viewstate CS 351 Ed Gellenbeck. Today Review of Web Forms ASP.NET Object Hierarchy Events State Management Page State Session State Application.

Slides:



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

1111 Creating ASPX Controls Programatically Objectives You will be able to Dynamically add controls to a page. Dynamically alter properties of controls.
11 ASP.NET Controls II Beginning ASP.NET 4.0 in C# 2010 Chapter 6.
Asp.NET Core Server Controls. Slide 2 Lecture Overview Understanding the types of ASP.NET controls HTML controls ASP.NET (Web) controls.
Anatomy of an ASP.NET Page. Slide 2 My Version of the Big Picture (1) ASP Worker (Engine) Your application Runs Server Other applications User 1User 2.
COS 381 Day 23. © 2006 Pearson Addison-Wesley. All rights reserved Agenda Capstone progress report Overdue –Only received 1 out of 6 Capstone projects.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 3-1 of…
Introduction to ASP.NET, Second Edition2 Chapter Objectives.
Server-Side Scripting with ASP.Net ISYS 546. ASP.NET ASP.NET is a server-side technology for creating dynamic web pages. ASP.NET allows you to use a selection.
Introduction to ASP.NET
11 ASP.NET Controls Beginning ASP.NET 4.0 in C# 2010 Chapter 6.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College Lecture 8: WebForms — Web-based.
Web Form Fundamentals MacDonald Ch. 5 MIS 324 MIS 324 Professor Sandvig Professor Sandvig.
9-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
OOP and Web Applications Michael Juřek Architect Evangelist Microsoft Corporation.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
HTML, GUI, ASP.NET Rina Zviel-Girshin Lecture 2
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College
1 ASP.NET. 2 ASP.NET Architecture ASP.NET uses the CLR to replace the existing ISAPI/ASP infrastructure of IIS with a more efficient and easier-to-use.
Overview of Previous Lesson(s) Over View  Server controls are small building blocks of the graphical user interface, which includes  Text boxes  Buttons.
February 16, Aaron Cuffman Andy Nagle Adam Schultz Web Site.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
1 Web Forms Andy Scrase.NET developer, Christchurch NZ
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 Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
ASP.NET Web Server Controls Basic Web Server Controls.
Web Controls Chapter-7. Page  2 Synopsis  Stepping Up to Web controls  Basic Web control classes  Web control classes  Web control Base class  Units,
© Minder Chen, ASP.NET 2.0: Introduction - 1 ASP.NET 2.0 Minder Chen, Ph.D. Framework Base Class Library ADO.NET: Data & XML.
Chapter 4 – Working with ASP.NET Controls Dr. Stephanos Mavromoustakos.
ASP.NET Controls. Slide 2 Lecture Overview Identify the types of controls supported by ASP.NET and the differences between them.
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.
Murach’s ASP.NET 4.0/VB, C1© 2006, Mike Murach & Associates, Inc.Slide 1.
1 CS 3870/CS 5870 Note04 Session Variables and Post Back.
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.
© 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.
Overview of Previous Lesson(s) Over View  SDI programs  The Application Wizard can generate single-document interface (SDI) applications that work.
Server Control Tips & Tricks Presented by: Patrick Hynds Microsoft Regional Director CriticalSites CTO MCSD, MCSE+I, MCDBA, MCSA, MCP+Site Builder, MCT.
STATE MANAGEMENT.  Web Applications are based on stateless HTTP protocol which does not retain any information about user requests  The concept of state.
Anatomy of an ASP.NET Page. Slide 2 Compiling an ASP.NET Page An ASP.NET page is compiled when it is rendered for the first time A page is compiled to.
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.
Beginning ASP.NET (Part 3).NET 2.0 Core Libraries Tuc Goodwin.
The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of.
ASP.NET 4 Unleashed Chapter 1. .aspx page: contains C# script and HTML code including tags. Listing 1.1 FirstPage.aspx.
Christopher M. Pascucci.NET Programming: WebForm Events.
Understanding Web Applications Lesson 4. Objective Domain Matrix Skills/ConceptsMTA Exam Objectives Understanding Web Page Development Understand Web.
MIS 3200 – Unit 3.2 Page_Load method AutoPostBack property of controls IsPostBack method of the Page object Understanding web page life cycle.
Asp.NET Core Server Controls. Slide 2 Lecture Overview Understanding the types of ASP.NET controls HTML controls ASP.NET (Web) controls.
11 ASP.NET Server Controls Beginning ASP.NET in C# and VB Chapter 4.
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.
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.
Sergey Sidorov PhD student, computer software chair Computer Science department.
ASP.NET Architecture Mike Taulty Developer & Platform Group Microsoft Ltd
ASP.NET State Management Overview Prepared By Manish Kumar Aery(IM66) Department of computer Application IET Bhaddal (Ropar)
ASP.NET Part 2 Instructor: Charles Moen CSCI/CINF 4230.
E-Commerce: Introduction to ASP.Net Application Architecture 1 Dr. Lawrence West, Management Dept., University of Central Florida Topics.
Computing with C# and the .NET Framework
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Working with ASP.NET Server Controls
Session Variables and Post Back
Chapter 8 User Controls.
Introduction to Client-Server Programming
Static and Dynamic Web Pages
ASP.NET.
Web Development Using ASP .NET
5/6/2019 Session 8.2 Postback, ViewState
Presentation transcript:

Event Handling & Viewstate CS 351 Ed Gellenbeck

Today Review of Web Forms ASP.NET Object Hierarchy Events State Management Page State Session State Application State

ASP Web Form A Web Form is a text file containing markup that can be edited in a simple text editor such as notepad. Contains a page directive Global settings for the page Contains blocks of code that are processed on the server The first time a Web form is requested, the entire page is compiled. Subsequent requests are served from this compiled page. Contains HTML and Web Controls

What’s the big deal? Web Forms are Object-oriented Event-based Efficient (compiled) Provide automatic state management

ASP.NET Object Hierarchy The Web Page is an object With properties, methods, and events page.IsPostBack, page.User, page.FindControl(),... Web Controls are objects With properties, methods, and events Have access to the entire.NET Framework class hierarchy With properties, methods, and events

Web Control Hierarchy Control WebControl ButtonTextBoxLabel TemplateControl PageUserControl... ID Page Visible Font Width Height Text Rows Columns TextRequest Response IsPostBack

Control Class public class Control:... { public virtual string ID { get; set; } public virtual ControlCollection Controls { get; } public virtual Control Parent { get; } public virtual Page Page { get; set; } public virtual bool Visible { get; set; } protected virtual StateBag ViewState { get; } public virtual bool EnableViewState { get; set; }... public virtual bool HasControls(); public virtual Control FindControl (string id); public virtual void DataBind(); protected virtual void LoadViewState (object state); protected virtual object SaveViewState(); protected virtual Render (HtmlTextWriter w);... public event EventHandler Init; public event EventHandler Load; public event EventHandler DataBinding; public event EventHandler PreRender; public event EventHandler Unload;... } Properties name of the control nested controls enclosing control page to which the control belongs should the control be visible? state of this control (see later) should the state be persistent? Methods does the control have nested controls? searches for a nested control with the name id loads data from a data source loads the state from the request stream saves the state to the response stream renders the control to HTML Events after the control was created after the state was loaded from the request after DataBind was called before the control is rendered to HTML before the control is released

Events Client-side Typically implemented with JavaScript and handled in the browser Server-side Slower because it involves round-trip to the server More powerful because methods have access to server resources

<asp:Button Text="..." OnClick="DoClick" Runat="sever" /> Event-based Processing mouse click void DoClick (object sender, EventArgs e) {... } ClientServer event handler click event

ControlEventWhen does the event occur? allInit Load PreRender Unload when the control is created after the data that were sent by the browser have been loaded into the control before HTML code for this control is generated before the control is removed from memory ButtonClickwhen the button was clicked TextBoxTextChangedwhen the contents of the TextBox changed CheckBoxCheckedChangedwhen the state of the CheckBox changed ListBoxSelectedIndexChangedwhen a new item from the list has been selected Kinds of Events

Round Trip of a Web Page Click ClientServer round trip event + page state 1. Creation create page object and its controls Page Label TextBox Button

ClientServer 2. Initialisation -raise Init events Init Click round trip event + page state Page Label TextBox Button

ClientServer 3. Loading -load controls with the values that the user has entered (page state) -raise Load events Load Click round trip event + page state Page Label TextBox Button

ClientServer 4. Action handle event(s) (Click, TextChanged,...) Page Label TextBox Button

ClientServer 5. Rendering -raise PreRender events -call Render methods of all controls, which render the controls to HTML PreRender page state HTML Page Label TextBox Button

ClientServer 6. Unloading -raise Unload events for cleanup actions Unload Page Label TextBox Button

Round trip events (cause an immediate round trip) Click <asp:Button Text="click me" Runat="server" OnClick="DoClick" /> Delayed events (are handled at the next round trip) TextChanged <asp:TextBox Runat="server" OnTextChanged="DoTextChanged" /> AutoPostBack (causes a delayed event to lead to an immediate round trip) TextChanged <asp:TextBox Runat="server" AutoPostBack="true" OnTextChanged="DoTextChanged" />

State Management HTTP is a stateless protocol Each Web request is acted upon as a independent action, with no previous history or data taken into account Most Server-Side technologies have some mechanism to save page session application state data

ASP.NET State Management Page state saving: ViewState["counter"] = counterVal; reading: int counterVal = (int) ViewState["counter"]; Session state saving:Session["cart"] = shoppingCart; reading:DataTable shoppingCart = (DataTable) Session["cart"]; Application state saving:Application["database"] = databaseName; reading: string databaseName = (string) Application["databaseName"];