Jim Fawcett CSE691 – Comparative Platforms Summer 2007

Slides:



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

WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
11 Getting Started with ASP.NET Beginning ASP.NET 4.0 in C# 2010 Chapters 5 and 6.
Web Development in Microsoft Visual Studio Slide 2 Lecture Overview Introduce Visual Studio 2013 Create a first ASP.NET application.
Introduction to ASP.NET, Second Edition2 Chapter Objectives.
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.
ASP.NET Programming with C# and SQL Server First Edition
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.
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.
© 2004 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin Programming the Web Using ASP.Net Chapter 2: The ASP.Net Template Dave.
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
JavaScript & jQuery the missing manual Chapter 11
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
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 Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 4-1 of…
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.
© Minder Chen, ASP.NET 2.0: Introduction - 1 ASP.NET 2.0 Minder Chen, Ph.D. Framework Base Class Library ADO.NET: Data & XML.
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
ASP.NET application. Roadmap ASP.NET file types Bin directory Application updates Simple application from start to finish using a virtual directory Behind.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
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.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Programming with Visual Web Developer Chapter 9.
Murach’s ASP.NET 4.0/VB, C1© 2006, Mike Murach & Associates, Inc.Slide 1.
C# Tutorial -1 ASP.NET Web Application with Visual Studio 2005.
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.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
1111 Creating ASPX Controls Programatically Objectives You will be able to Dynamically add controls to a page. Dynamically alter properties of controls.
11 Getting Started with ASP.NET Beginning ASP.NET in C# and VB Chapters 1 and 2.
11 User Controls Beginning ASP.NET in C# and VB Chapter 8.
Creating a Web Site Creating a new Web site Defining and using folders Creating and editing Web pages Viewing pages in a Web browser.
Introduction to ASP.NET development. Background ASP released in 1996 ASP supported for a minimum 10 years from Windows 8 release ASP.Net 1.0 released.
ASP.NET Part 2 Instructor: Charles Moen CSCI/CINF 4230.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Chapter 1 Getting Started with ASP.NET Objectives Why ASP? To get familiar with our IDE (Integrated Development Environment ), Visual Studio. Understand.
Jim Fawcett CSE686 – Internet Programming Spring 2014
Jim Fawcett CSE686 – Internet Programming Spring 2014
Computing with C# and the .NET Framework
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
ASP.NET Forms.
Working with ASP.NET Server Controls
Jim Fawcett CSE686 – Internet Programming Spring 2012
Session Variables and Post Back
Web Application Web Application are programs that can be executed either on a Web server or in a Web browser. An Online store accessed through a browser.
ASP Explained By: Sarbjit Kaur.
Web Forms, HTML, and ASP.NET
Introduction to Client-Server Programming
Haritha Dasari Josue Balandrano Coronel -
Active Server Pages ASP.Net
Unit 27 - Web Server Scripting
Chapter 23 – ASP.NET Outline 23.1 Introduction NET Overview
Web Development in Microsoft Visual Studio 2013
Client side & Server side scripting
ASP.NET
Static and Dynamic Web Pages
ASP.NET.
Web Development Using ASP .NET
Chapter 9 Programming with Web Forms
Presentation transcript:

Jim Fawcett CSE691 – Comparative Platforms Summer 2007 ASP.Net – Part I Jim Fawcett CSE691 – Comparative Platforms Summer 2007

Starting a Website

Starting a Website Visual Studio builds Asp.Net applications in two directories: Web site files are placed in a folder you specify when creating the website. This directory holds the files: Default.aspx Default.aspx.cs Your solution goes in a folder you specify on Tools\Options\Projects and Solutions. This directory holds the files: WebsiteName.sln WebsiteName.suo To move the website, simply copy the files from the Website directory to the new location, and make this a virtual directory with anonumous access enabled. You will also have to set the application in the directory’s properties page.

Website Files Note: no project

ASP Application Files Test.aspx Test.aspx.cs Other things you can add: An ASP page providing the user interface for the application, used to build the processed page. Test.aspx.cs A C# WebForm, with structure somewhat like a WinForm that serves as base class for the Test class and, in turn, derives from System.Web.UI.Page. Other things you can add: Web.config Allows you to set debug tracing and other session related properties Additional Forms User defined controls StyleSheets Script files

Adding Additional Items

Setting Location of Website Solution

Setting Location of Website Location of website. You can change the path and name to whatever you wish. This is were the Virtual Directory will be created, and the initial WebForm depositied.

Changing the location of a website You can change the location of a website: Create a new virtual Directory Copy the files from the original virtual directory In Windows Explore or the IIS Snapin Remove the application from the original directory

Virtual Directory Viewed from Windows Explorer

Virtual Directory Viewed in IIS Snapin

Running from New Location

Server-Side Programs You can run any .Net webform that resides in a virtual directory simply by requesting it from a browser: http://www.ecs.syr.edu/faculty/fawcett/handouts/CSE686/code/AspApps/BasicAsp/PickAgain.aspx Provided that directory permissions allow this. On Windows platforms most server-side processing takes the form of Active Server Page (ASP) applications or ASP.Net applications. Note that most of the examples I’ve placed on the college server will run from there, as that server has .Net and IIS installed. To run the examples from your own machine, just FTP the code folder to any directory on your local machine, in Windows Explorer right click on the folder, select properties, and select web sharing. Now you can open the site with http://localhost/setName/formName.aspx

Traditional ASP Traditional (pre .Net) ASP provides interpreted application scripts running in the memory space of the IIS web server. A traditional ASP page consists of a mix of HTML, sent directly to the requesting browser and Javascript or Vbscript executed on the server, usually to generate html for display or interact with a backend database. Traditional ASP uses a set of standard server side COM objects and can use custom COM objects as well. Deploying custom COM objects to remote servers has been a major problem.

Server-Side Objects Traditional ASP provides seven objects used for server-side programming: Application: starts when IIS starts and runs until IIS shuts down ASPError ASPError object is returned by Server.GetLastError(), and has the properties: Source, Category, File, Line, Description, ASPDescription ObjectContext Access to COM+ objects Request: Provides methods: Form(), QueryString(), Cookies(), ServerVariables() Response: Provides methods: Write(), Clear(), End(), Flush(), Redirect(), Buffer, Expires, IsClientConnected(), PICS() Server: Provides methods: Execute(), Transfer(), MapPath(), URLEncode(), HTMLEncode(), GetLastError() Session: starts when a user requests first page and ends with a timeout

ASP .Net ASP.Net supports the traditional style, but adds processing power of compiled C# and a pervasive object model. We can create user-defined classes in C# and use them on ASP pages. Any .Net language can be used this way. Web controls are based on CLR objects. Control state is sent back and forth between client and server in a hidden viewstate. An ASP.Net page can easily be turned into a server control that can be used on any other ASP page.

ASP.Net Environment

ASP.Net WebForm An ASP.Net page has: A single form control: <form id=“form1” runat=“server”> … </form> Zero or more server controls: That render themselves to HTML Have methods, properties, and events Server controls come in two flavors: HTML controls that have html tags <input id=“Checkbox1” type=“checkbox” /> Standard (Web) controls <asp:Button ID=“Button1” runat=“server” Text=“…” />

Page Rendering Model When an aspx page is requested, a Page object is instantiated, and an object is created for each control on the page. Each of the control objects is added to the page’s controls collection. When the page renders: It generates HTML representing the form Calls each of its controls to render itself, resulting in: HTML generated for each control. Javascript that generates a postback to the server each time the client takes some action that triggers a client-side HTML-based event.

The First Call The first time a page is loaded after creation or a change to its text: ASP.Net parsers extract code from the codebehind file and build a class, derived from System.Web.UI.Page, that contains a collection for the page’s controls, renderning code, events, … The aspx file is parsed, and a class, derived from the code behind-based class, is built to render the page.

Page Serving Model

ASP.Net Page Contents An ASP.Net page contains: Directives for the compiler, which must include a <@Page … > directive. Literal HTML content, intended for the client Code in C#, VB, Jscript.Net. The Code will: Respond to client-side events that result in a PostBack to the server and may also: generate HTML for client get or send data to a database on this or a remote server interact in some way with the server’s file system Traditional script, e.g.: Javascript or Vbscript Embedded ASP.Net server controls Means to collect information from, and present information to, clients Control state is preserved in transactions between client and server using a hidden viewstate. Server HTML controls, based on the traditional HTML controls Also manages information between client and server. Preserving state requires more work on programmer’s part.

Page GET Life Cycle Browser issues an HTTP GET request for an aspx page. The IHttpHandler::ProcessRequest method is called. Handler creates a Page-derived class by loading the aspx page specified in the request, and loading any requred dynamic link libraries (dlls), residing in the application’s bin directory. Server calls Page’s ProcessRequest, which results in a recursive call to __Render__control for the page and each of its child controls. Each control’s __Render__control call is responsible for constructing html for it’s own part of the page display.

Page POST Life Cycle Any event triggered by a user action in the client browser generates a submit request and subsequent HTTP POST message. The body of the message contains data from the form to be processed on the server. POSTed data is captured by the server’s request object and processed by event handlers in the original aspx page’s C# Codebehind. This processing almost always results in more rendering and the page is then sent back to the client. Complete cycle: GET  reply  user action  POST  reply  user action … The Page.IsPostback property tells server code whether processing is in response to a GET or a POST command.

What’s So Great about Asp.Net? The object model, with its Page class that supports Asp.Net pages, is extremely helpful in building effective websites: We can build a Page derived class that will serve as a base class for all our web pages that contains all the code common to pages in the site: styles controls (navigation bar and user access control for example) Headers and Footers User defined controls are easy to define and reuse. All of the power of the .Net framework is available for our server-side processing, e.g.: directory and file manipulation Regular expression analysis XML processing Web services Advanced data management classes

ASP .Net Applications You can build an ASP application using notepad to create an aspx page, a C# code page, and, optionally, a web.config file. Here’s what is required to do that: Create an aspx file that has: Page directive that contains an Inherits attribute that specifies a class from the code page, e.g., Inherits=“_Default” HTML including a form and one or more controls Create a codebehind cs file that contains: Event handlers for each of the aspx control events you want to handle Helper code Make each of these members of a class derived from System.Web.UI.Page Declare protected fields with names the same as the IDs of the controls on the aspx page, e.g., TextBox UserName; Compile the cs file into a library dll and place the dll in a bin subdirectory immediately below the aspx application. Of course, you can do that quickly by running the website wizard.

Page Hierarchy using Reflection Hierarchy discovered by using reflection in Form_Load, e.g., GetType(), GetType().BaseType, and GetType.BaseType.BaseType

HTMLServer Controls Input: Button, Reset, Submit, Text, File, Password, Checkbox, Radio, Hidden Textarea, Table, Image, Select, Horizontal Rule, Div <INPUT id=“UserID” style=“…” type=“text” runat=“server”> Allows you to take any valid html page and change its extension to aspx and have it run as an ASP.Net application. This makes migration from older sites somewhat easier.

WebServer Controls Label, TextBox, Button, LinkButton, ImageButton, HyperLink, DropDownList, ListBox, CheckBox, CheckBoxList, RadioButton, Image, ImageMap, Table, BulletedList, HiddenField, Literal, Calendar, AdRotator, FileUpLoad, Xml, MultView, Panel, PlaceHolder, View, Substitution, Localize <asp:Label id=“Label1” runat=“server” BorderColor=“maroon”>default text</asp:Label> Richer behavior, styles, and configurations than HTML controls.

Server Controls WebServer Controls These controls have state which is marshalled between client and server in a hidden ViewState variable. Events, like button clicks, that happen on the client side, are marshalled back to the server to trigger event handlers in C#, processed on the server. This event model is based on encapsulated Javascript processing that posts page data back to the server when a specific event occrurs.

Let’s Build an Application Create an ASP.Net Application, using C# Pull a TextBox, Button, and Label onto the form. Switch to HTML view and put a couple of <br/> tags between each of these controls. Add some styling in the head section. Double click on the form to generate a Page_Load event handler and we will put some code there. Double click on the button and we’ll also put some code there. Run the application.

Design View

ASPX Code View

C# Code View

CodeFile ///////////////////////////////////////////////////////////////////// // Default.aspx.cs - Simple Asp.Net demo // // // // Jim Fawcett, CSE686 - Internet Programming, Summer 2006 // using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) if (IsPostBack) Label1.Text = "You entered \"" + TextBox1.Text + "\""; Label1.Text = Label1.Text + "<br/><br/> Page Type is: " + this.GetType(); Label1.Text = Label1.Text + "<br/> Base Type is: " + this.GetType().BaseType; Label1.Text = Label1.Text + "<br/> Base of that is: " + this.GetType().BaseType.BaseType; }

Running Default.aspx

References Pro ASP.Net 2.0 in C# 2005, MacDonald & Szpuszta, Apress, 2006 Programming Microsoft .Net, Jef Prosise, Microsoft Press, 2002 ASP.NET Unleashed, Second Edition, Stephen Walther, SAMS, 2004 ASP.Net, Tips, Tutorials, and Code, Mitchell, et. al., SAMS, 2002 More examples (a lot in Visual Basic.Net, some in C#) than most of the other books available on ASP. http://samples.gotdotnet.com/quickstart/aspplus/ has some interesting tutorial material on ASP.Net.