Object Oriented Programming Web forms, web controls and ASP.NET Dr. Mike Spann

Slides:



Advertisements
Similar presentations
11 Getting Started with ASP.NET Beginning ASP.NET 4.0 in C# 2010 Chapters 5 and 6.
Advertisements

Web Development in Microsoft Visual Studio Slide 2 Lecture Overview Introduce Visual Studio 2013 Create a first ASP.NET application.
Web-Based Applications
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 3-1 of…
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
1 Chapter 20 — Creating Web Projects Microsoft Visual Basic.NET, Introduction to Programming.
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.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
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.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
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.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
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.
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
CIS 375—Web App Dev II ASP.NET 2 Introducing Web Forms.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Module 7: Validating User Input.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
Dr. Azeddine Chikh IS444: Modern tools for applications development.
HTML, GUI, ASP.NET Rina Zviel-Girshin Lecture 2
An Introduction to ASP.NET Ed Dunhill blogs.msdn.com/edunhill SLIDE7.
Telerik Software Academy ASP.NET Web Forms Data Validation, Data Validators, Validation Groups Telerik Software Academy
Overview of Previous Lesson(s) Over View  Server controls are small building blocks of the graphical user interface, which includes  Text boxes  Buttons.
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.
Programming with Microsoft Visual Basic 2012 Chapter 12: Web Applications.
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…
Creating Web Applications Using ASP.NET Chapter Microsoft Visual Basic.NET: Reloaded 1.
Chapter 9 Programming with Web Forms Programming In Visual Basic.NET.
JSP Java Server Pages Softsmith Infotech.
ASP.Net, Web Forms and Web Controls 1 Outline Web Controls Text and Graphics Controls AdRotator Control Validation Controls.
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.
ASP.NET Controls. Slide 2 Lecture Overview Identify the types of controls supported by ASP.NET and the differences between them.
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.
Object Oriented Programming Web forms, web controls and ASP.NET Dr. Mike Spann
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.
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.
Microsoft Visual Basic 2005 CHAPTER 7 Creating Web Applications.
Object Oriented Software Development 9. Creating Graphical User Interfaces.
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.
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.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
IT533 Lectures ASP.NET AJAX.
Asp.NET Core Server Controls. Slide 2 Lecture Overview Understanding the types of ASP.NET controls HTML controls ASP.NET (Web) controls.
Chapter 27 Getting “Web-ified” (Web Applications) Clearly Visual Basic: Programming with Visual Basic nd Edition.
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.
Text INTRODUCTION TO ASP.NET. InterComm Campaign Guidelines CONFIDENTIAL Simply Server side language Simplified page development model Modular, well-factored,
Creating a Web Site Creating a new Web site Defining and using folders Creating and editing Web pages Viewing pages in a Web browser.
ASP.NET Part 2 Instructor: Charles Moen CSCI/CINF 4230.
ASP.NET Forms.
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.
Unit 27 - Web Server Scripting
Static and Dynamic Web Pages
ASP.NET.
Web Development Using ASP .NET
Chapter 9 Programming with Web Forms
Programming with Microsoft Visual Basic 2008 Fourth Edition
Presentation transcript:

Object Oriented Programming Web forms, web controls and ASP.NET Dr. Mike Spann

Contents Introduction Introduction Static and dynamic web pages Static and dynamic web pages How ASP.NET works How ASP.NET works Introduction to web form programming Introduction to web form programming Visual Web Developer Visual Web Developer Validation controls Validation controls Summary Summary

Static and dynamic web pages We are all familiar with the concept of clients and web servers Clients issue requests (using the http protocol) to web servers for web pages The server responds with a message packet containing html which is the encoded web page The web browser program running on the client parses the html and displays the web page

Static and dynamic web pages Internet Client Server http GET request http response plus html document

Static and dynamic web pages Static web pages appear the same in response to every request from the client to server   This is typical of simple html web pages Dynamic pages can change depending on data supplied from the client or be personalised for the user based on cookies which are installed on the client computer   There are many technologies which support this of which ASP.NET is a powerful Microsoft example   Essentially it involves running asp scripts supported by code written in a high level language (typically VB or C#) on the server on which.NET has been installed

Static and dynamic web pages For example, we can create a static web page to display times of movies as a cinema For example, we can create a static web page to display times of movies as a cinema  html html html The problem with this is that the information cannot be updated without altering the html code The problem with this is that the information cannot be updated without altering the html code  html consists of tags followed by text  The text is interpreted according to the enclosing tags by the web browser

Static and dynamic web pages Movie Magic Cinema Welcome to a James Bond evening Showtimes for Wed 10/31 The Man With The Golden Gun 1:05 pm, 3:25 pm, 7:00 pm Diamonds Are Forever 12:50 pm, 3:25 pm, 6:55 pm The World Is Not Enough 3:30 pm, 8:35 pm From Russia With Love 12:45 pm, 6:45 pm

Static and dynamic web pages We can modify our static web page to include some dynamic content We can modify our static web page to include some dynamic content  It will display the current date/time along with the movie schedule  We will use ASP.NET to run server side code Net stuff/MovieSite/MovieSite.aspxhttp:// Net stuff/MovieSite/MovieSite.aspxhttp:// Net stuff/MovieSite/MovieSite.aspxhttp:// Net stuff/MovieSite/MovieSite.aspx The site will be an.aspx file which will look similar to our original.html file The site will be an.aspx file which will look similar to our original.html file  It will call methods from a C# class which is in a code behind file We will explain later how this all fits together We will explain later how this all fits together

Static and dynamic web pages Movie Magic Cinema Welcome to a James Bond evening Showtimes for

Static and dynamic web pages 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 MoviePage : System.Web.UI.Page { protected void WriteDate() { this.Response.Write(DateTime.Now.ToString()); } protected void WriteMovies() { this.Response.Write( " The Man With The Golden Gun 1:05 pm, 3:25 pm, 7:00 pm pm "); this.Response.Write( " Diamonds Are Forever 12:50 pm, 3:25 pm, 6:55 pm "); this.Response.Write( " The World Is Not Enough 3:30 pm, 8:35 pm "); this.Response.Write( " From Russia With Love 12:45 pm, 6:45 pm "); }

How ASP.NET works To create a dynamic web page, we create an.aspx file To create a dynamic web page, we create an.aspx file  If the client requests an.aspx file, because of the file extension, the file is forwarded to ASP.NET by the web server  ASP.NET parses the.aspx file  It understands.html tags as well as ASP tags ( )  Ultimately ASP.NET will create an object, using the code in the.aspx file and the codebehind (C#) file which produces the.html to send back to the client

How ASP.NET works.aspx file.cs file Web server ASP.NET Page derived managed object

How ASP.NET works Web server ASP.NET Page derived managed object html To client

How ASP.NET works From the 2 files, ASP.NET produces code for 2 files From the 2 files, ASP.NET produces code for 2 files  The class is derived from the System.Web.UI.Page class (which contains basic functionality to produce html)  Also System.Web.UI.Page contains functionality to parse the request from the client including attached postback data  ASP.NET creates an instance of this object to represent the page

How ASP.NET works The real power of ASP.NET is that the production of html is abstracted away to managed components The real power of ASP.NET is that the production of html is abstracted away to managed components  For example, a button on a web form knows how to produce the html to render itself on the web page  All these components exist in the namespace System.Web.UI.WebControls  It’s state may depend on postback data from the client so the component may need to re-render itself in response

How ASP.NET works Browser-Client Web server ASP.NET Browser clientInternet Managed code html Browser request and postback data Page derived and custom objects

How ASP.NET works In our simple example, code for a derived class of the MoviePage class is produced In our simple example, code for a derived class of the MoviePage class is produced  An object is instantiated containing code for method calls to WriteDate() and WriteMovies() More realistically our page will contain web controls which represent user interface elements on our web page More realistically our page will contain web controls which represent user interface elements on our web page  These are defined in the FCL  We can design a web page using visual programming techniques to drag and drop these controls into our page  We don’t have to worry about producing the right html to send back to our browser

How ASP.NET works Another key feature of ASP.NET is its runtime performance Another key feature of ASP.NET is its runtime performance ASP.NET parses the.aspx files at runtime ASP.NET parses the.aspx files at runtime  Code is compiled into binary assemblies (.dll files) which are cached and reused  A web form application must only be parsed once after each modification to source files  On receiving a request from the client, ASP.NET looks for an already compiled assembly to fulfil the request otherwise it creates one from the submitted.aspx file and code-behind file

Introduction to web form programming Web form programming allows us to insert web controls (for example buttons, labels, images etc) into web pages Web form programming allows us to insert web controls (for example buttons, labels, images etc) into web pages We can do this programmatically in the.aspx and codebehind files We can do this programmatically in the.aspx and codebehind files Or we can do this using the design view in Visual Studio Or we can do this using the design view in Visual Studio It allows us to design interactive webpages whose visual representation changes in response to user interaction It allows us to design interactive webpages whose visual representation changes in response to user interaction

Introduction to web form programming ControlDescription AdRotator Implements a rotating banner add. Button Implements a button for web user interface. Calendar Implements a highly configurable calendar UI. CheckBox Implements a check box for web UI. DataGrid Implements a table that supports automatic binding to data sources. HyperLink Implements a dynamic hyperlink. Image Implements an image for inclusion in web UI. Label Implements a dynamic label or text output. LinkButton Implements a hyperlink style button. ListControl Implements a list box for web UI. Panel A virtual control that is a collection of controls. This control is useful for treating a block of controls as a single entity. For example, it is easy to create a Panel to cause blocks of controls to appear or disappear from the rendered HTML. Table Implements a simple table with custom rows and cells. TextBox Implements an editable text box for web UI. RangeValidator Implements a validator that assures that an entry in another control on the page falls within a given range. Validator controls automatically generate client-side script to perform validation for browsers that support JScript. Whether or not validation is performed on the client side, validation is also performed on the server side by the control. RequiredFieldValidator Implements a validator that assures that an entry was made to a field.

Introduction to web form programming As a simple example, the following website allows the month’s calendar to be displayed for any user inputted date As a simple example, the following website allows the month’s calendar to be displayed for any user inputted date  It demonstrates the use of the button, label, textbox and calendar web controls  Controls.aspx Controls.aspx Controls.aspx

Introduction to web form programming Demonstrating simple web controls Enter a Date Here <asp:Button id="button" Text="Then press this button" runat="server“/ >

Introduction to web form programming using System; using System.Web.UI; using System.Web.UI.WebControls; public partial class DatePage : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { button.Click += new EventHandler(OnButtonClicked); } protected void OnButtonClicked(Object sender, EventArgs args) { String dateString = date.Text; try { DateTime enteredDate = Convert.ToDateTime(dateString); calendar.SelectedDate = enteredDate; calendar.VisibleDate = enteredDate; calendar.Visible = true; } catch (FormatException) { calendar.Visible = false; }

Introduction to web form programming The tag in the.aspx file indicates that we are defining a web control The tag in the.aspx file indicates that we are defining a web control  asp: is shorthand for the System.Web.UI.WebControls namespace  The runat=“server” attribute for each web control indicates that these controls are to be implemented on the server side  We are setting the properties of our web control objects in the but we could also use the properties window in Visual Studio

Visual Web Developer A sub-set of Visual Studio is the Visual Web Developer which has a visual designer based on Front Page A sub-set of Visual Studio is the Visual Web Developer which has a visual designer based on Front Page  Allows the developer to use ‘drag and drop’ to insert web controls into web pages  Code can then easily be added to the codebehind files  Typically this would be event handler functions for the controls

Visual Web Developer We select File->New->Web site and then select ASP.NET Web Site We select File->New->Web site and then select ASP.NET Web Site  Normally HTTP is selected and the location (in this case means under the local ‘wwwroot’ directory (assuming IIS has been installed locally)

Visual Web Developer Web Developer has a design mode rather similar to the design mode we used to create GUI’s in normal windows programming Web Developer has a design mode rather similar to the design mode we used to create GUI’s in normal windows programming It differs slightly in that there is a cursor position and any web controls or text are added at the current cursor position It differs slightly in that there is a cursor position and any web controls or text are added at the current cursor position  The.aspx file is updated as the web site is created in design mode  The currently designed website can be previewed at any time  As in normal windows program development, the event handler code for web controls (eg buttons) have to be added by the developer

Visual Web Developer We can create the web page for displaying the calendar using design mode We can create the web page for displaying the calendar using design mode The label, text field, button and calendar are inserted into the page using drag and drop The label, text field, button and calendar are inserted into the page using drag and drop  We set the visible property of the calendar to false in its properties window  We set the background colour of the outer form using the properties windon  All code except the Page_Load() and Button_Click()methods is automatically created

Visual Web Designer Demo

Validation controls A validation control determines whether the data entered in a web control is in the proper format A validation control determines whether the data entered in a web control is in the proper format  For example a postcode entered in the correct alphanumeric format  A date entered in the correct dd/mm/yyyy format  A correct address is entered  etc The validation check is carried out by the client by converting the validator to Javascript to perform the validation before submitting the data to the server The validation check is carried out by the client by converting the validator to Javascript to perform the validation before submitting the data to the server

Validation controls Validation controls can be input onto a webpage using Visual Web Developer Validation controls can be input onto a webpage using Visual Web Developer  Actual validators for things like phone numbers, addresses are defined by regular expressions  These are strings containing formatting characters used to match to particular patterns in text  We can define our own regular expressions as validators for particular inputs  Luckily however, Visual Web Developer has a regular Expression Editor dialog box allowing us to choose standard regular expressions for things like addresses and phone numbers

Validation controls For example we can create a simple web form to input a name, address and phone number into textboxes and include input validators for each For example we can create a simple web form to input a name, address and phone number into textboxes and include input validators for each  We can also make each input a required field so that each field must be input before submitting to the server We also include a label at the bottom of the form for the server response We also include a label at the bottom of the form for the server response  The visible property of this label is initially set to false NET stuff/ValidationControls/Validation.aspx NET stuff/ValidationControls/Validation.aspx NET stuff/ValidationControls/Validation.aspx NET stuff/ValidationControls/Validation.aspx

Validation controls We can add required field validators to each of our input textboxes We can add required field validators to each of our input textboxes  We can set the ControlToValidate and ErrorMessage properties in the properties window of each validation control  The validation controls remain invisible in the website unless an input is not added before the form is submitted  The required error message is displayed  The form is not submitted to the server

Validation controls Next we can add RegularExpression validators to our input text boxes for and phone numbers Next we can add RegularExpression validators to our input text boxes for and phone numbers  We can use a standard regular expression for taken from the dialog which is obtained from the properties window   We can generate our own for a UK phone number  ((\(\+\d{2}\) ?)|(\+\d{2}-))?\d{3}-\d{3}-\d{4} eg (+44)( )eg (+44)( )

Demonstrating Validation Controls Please fill out the following form All fields are required and must be in the valid format <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2" ErrorMessage="Please enter your address" ForeColor="Blue"> <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox2" Display="Dynamic" ErrorMessage="Please input your address in the correct format" ForeColor="Blue" <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBox3" Display="Dynamic" ErrorMessage="Please enter your telphone number"ForeColor="Blue"> <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TextBox3" Display="Dynamic" ErrorMessage="Please enter a phone number in valid format" ForeColor="Blue" ValidationExpression="((\(\+\d{2}\) ?)|(\+\d{2}-))?\d{3}-\d{3}-\d{4}"> <asp:Label ID="Label6" runat="server" Text="Thank you for filling out this form" Visible="False" Font-Italic="False">

Validation controls Its often useful to display the data that was submitted on the same web form Its often useful to display the data that was submitted on the same web form  In practice, this data would be stored on file or in a database We can do this using a postback event We can do this using a postback event  A postback event is raised in response to the client-side button click and causes the page to be loaded by ASP.NET at the server a second time  The IsPostBack property of Page is set to true if the page is re-loaded in response to a postback

Validation controls 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 Validation : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { string name = Request.Form["TextBox1"]; string =Request.Form["TextBox2"]; string phone=Request.Form["TextBox3"]; Label6.Text += " "; Label6.Text+="You have inputted the following "; Label6.Text+="Name: " + name +" "; Label6.Text+=" address: " + +" "; Label6.Text+="Phone number: " + phone +" "; Label6.Visible = true; }

Summary We have looked at the difference between static and dynamic web pages and how we can generate simple dynamic web pages We have looked at the difference between static and dynamic web pages and how we can generate simple dynamic web pages We have looked at how ASP.NET generates dynamic objects at the web server from.aspx files and C# codebehind files We have looked at how ASP.NET generates dynamic objects at the web server from.aspx files and C# codebehind files We have looked at simple web form programming We have looked at simple web form programming We have looked at the use of Visual Web Designer to build dynamic websites We have looked at the use of Visual Web Designer to build dynamic websites We have looked at how we can build in validation controls to our websites We have looked at how we can build in validation controls to our websites