E-commerce Applications Development

Slides:



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

JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
Asp.NET Core Server Controls. Slide 2 Lecture Overview Understanding the types of ASP.NET controls HTML controls ASP.NET (Web) controls.
JavaScript Forms Form Validation Cookies CGI Programs.
Creating Web Page Forms. Objectives Describe how Web forms can interact with a server-based program Insert a form into a Web page Create and format a.
1 Chapter 20 — Creating Web Projects Microsoft Visual Basic.NET, Introduction to Programming.
Tutorial 3: Adding and Formatting Text. 2 Objectives Session 3.1 Type text into a page Copy text from a document and paste it into a page Check for spelling.
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
Chapter 10 Form Basics Key Concepts Copyright © 2013 Terry Ann Morris, Ed.D 1.
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.
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.
XP Tutorial 6New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Creating Web Page Forms Designing a Product Registration Form Tutorial.
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.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
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.
XHTML Introductory1 Forms Chapter 7. XHTML Introductory2 Objectives In this chapter, you will: Study elements Learn about input fields Use the element.
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.
XP Dreamweaver 8.0 Tutorial 3 1 Adding Text and Formatting Text with CSS Styles.
ASP.NET Controls. Slide 2 Lecture Overview Identify the types of controls supported by ASP.NET and the differences between them.
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
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.
Web Form Fundamentals Chapter-2 Unit-2.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
HTML Forms.
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.
Week 9 - Form Basics Key Concepts 1. 1.Describe common uses of forms on web pages 2.Create forms on web pages using the form, input, textarea, and select.
Christopher M. Pascucci Basic Structural Concepts of.NET Managing State & Scope.
Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input.
Tutorial 3 Adding and Formatting Text with CSS Styles.
Copyright © Texas Education Agency, All rights reserved.1 Web Technologies Website Forms / Data Acquisition.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
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.
Text INTRODUCTION TO ASP.NET. InterComm Campaign Guidelines CONFIDENTIAL Simply Server side language Simplified page development model Modular, well-factored,
HTML Structure II (Form) WEEK 2.2. Contents Table Form.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
XP Tutorial 6New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
Creating Consistent Looking Websites
2440: 141 Web Site Administration Web Forms Instructor: Joseph Nattey.
Chapter 1 Getting Started with ASP.NET Objectives Why ASP? To get familiar with our IDE (Integrated Development Environment ), Visual Studio. Understand.
Tutorial 6 Working with Web Forms
Advanced HTML Tags:.
Fundamentals of a Web Form
Computing with C# and the .NET Framework
ASP.NET Forms.
Allowing File Uploads.
How to Write Web Forms By Mimi Opkins.
Chapter 8 User Controls.
Introduction to Client-Server Programming
ITE 115 Creating Web Page Forms
Designing Forms Lesson 10.
Unit 27 - Web Server Scripting
Client side & Server side scripting
MODULE 7 Microsoft Access 2010
FORM OBJECT When creating an interactive web site for the Internet it is necessary to capture user input and process this input. Based on the result of.
CNIT 131 HTML5 - Forms.
ASP.NET.
Creating Forms on a Web Page
Web Development Using ASP .NET
5/6/2019 Session 8.2 Postback, ViewState
PHP-II.
Web Programming and Design
Allowing File Uploads.
Presentation transcript:

E-commerce Applications Development 0731465 Done by Raneem Qaddoura

Lecture 1 HTML server control (1)

Converting an HTML Page to an ASP.NET Page

Converting an HTML Page to an ASP.NET Page HTML Page This page has two <input> elements: one for the text box and one for the submit button. These elements are enclosed in a <form> tag, so they can submit information to the server when the button is clicked. The rest of the page consists of static text. <!DOCTYPE html> <html> <body> <form <div> convert: <input type="text“/> U.S. dollar to Euros. <br/><br/> <input type="submit" value="OK"/> </div> </form> </body> </html>

Converting an HTML Page to an ASP.NET Page Generate a new web form in Visual Studio Select Website ➤ Add New Item. In the Add New Item dialog box, choose Web Form Type a name for the new page (such as CurrencyConverter.aspx) Make sure the Place Code in Separate File option is checked Click Add to create the page.

Converting an HTML Page to an ASP.NET Page Generate a new web form in Visual Studio Delete everything that’s currently in the .aspx file, except the page directive <%@ Page Language="C#" AutoEventWireup="true" CodeFile="CurrencyConverter.aspx.cs" Inherits="CurrencyConverter" %> The page directive Gives ASP.NET basic information about how to compile the page. Indicates the language you’re using for your code and the way you connect your event handlers. Indicates where the code file is located and the name of your custom page class. Copy all the content from the original HTML page, and paste it into the new page, right after the page directive. Add the attribute runat="server" to each tag that you want to transform into a server control Add an ID attribute to each control that you need to interact with in code. The ID attribute assigns the unique name that you’ll use to refer to the control in code.

Converting an HTML Page to an ASP.NET Page <%@ Page Language="C#" AutoEventWireup="true" CodeFile="CurrencyConverter.aspx.cs" Inherits="CurrencyConverter" %> <!DOCTYPE html> <html> <body> <form runat="server"> <div> convert: <input type="text" id="US" runat="server"/> U.S. dollar to Euros. <br/><br/> <input type="submit" value="OK" id="convert" runat="server"/> </div> </form> </body> </html>

Converting an HTML Page to an ASP.NET Page Generate a new web form in Visual Studio To try this page, launch it in Visual Studio by pressing F5 Then, select View ➤ Source in your browser to look at the HTML that ASP.NET sent your way. HTML that was sent to the browser is slightly different from the information in the .aspx file. The runat="server" attributes are stripped out (because they have no meaning to the client browser, which can’t interpret them). An additional hidden field has been added to the form. This hidden field stores information, in a compressed format, about the state of every control in the page. It allows you to manipulate control properties in code and have the changes automatically persisted across multiple trips from the browser to the web server. If you enter information in the text box and click the submit button to post the page, the refreshed page will still contain the value you entered in the text box. In the original example that uses ordinary HTML elements, the value will be cleared every time the page is submitted. This change occurs because ASP.NET controls automatically retain their state

HTML control classes Class Name HTML element HtmlForm <form> HtmlAnchor <a> HtmlImage <img> HtmlTable, HtmlTableRow, and HtmlTableCell <table>,<tr>,<th>,and <td> HtmlInputButton, HtmlInputSubmit, and HtmlInputReset <input type=“button”>, <input type=“submiy”>, and <input type=“reset”> HtmlButton <button> HtmlInputCheckBox <input type=“checkbox”> HtmlInputRadioButton <input type=“radio”> HtmlInputText and HtmlInputPassword <input type=“text”> and <input type=“password”> HtmlTextArea <textarea> HtmlInputImage <input type=“image”> HtmlInputFile <input type=“file”> HtmlInputHidden <input type=“hidden”> HtmlSelect <select> HtmlHead and HtmlTitle <head> and <title> HtmlGenericControl Any other HTML element

Adding the Currency Converter Code In the simple currency converter page example, the most useful event occurs when the user clicks the submit button (named Convert). The HtmlInputButton allows you to react to this action by handling the ServerClick event. Before you continue, it makes sense to add another control that can display the result of the calculation. In this case, you can use a tag named Result. The tag is one way to insert a block of formatted text into a web page. Here’s the HTML that you’ll need: . <div runat="server" ID="Result" >…</div>

Adding the Currency Converter Code The example now has the following four server controls: A form (HtmlForm object). This is the only control you do not need to access in your code-behind class. An input text box named US (HtmlInputText object). A submit button named Convert (HtmlInputButton object). A tag named Result (HtmlGenericControl object). CurrencyConverter.aspx <form runat="server"> <div> convert: <input type="text" id="US" runat="server"/> U.S. dollar to Euros. <br/><br/> <input type="submit" value="OK" id="convert" runat="server“ OnServerClick="Convert_ServerClick" /> <div runat="server" ID="Result" >…</div> </div> </form>

Adding the Currency Converter Code CurrencyConverter.aspx.cs Using statements. This provides access to all the important namespaces. Include just the core ASP.NET namespaces in order to save space. When you create a web page in Visual Studio, it adds several more The page class is defined with the partial keyword. That’s because your class code is merged with another code file that you never see. This extra code, which ASP.NET generates automatically, defines all the server controls that are used on the page. This allows you to access them by name in your code. The page defines a single event handler. This event handler retrieves the value from the text box, converts it to a numeric value, multiplies it by a preset conversion ratio (which would typically be stored in another file or a database), and sets the text of the tag. The event handler is connected to the control event using the OnServerClick attribute in the tag for the button.

Adding the Currency Converter Code You’ll notice that the event handler accepts two parameters (sender and e). This is the .NET standard for all control events. It allows your code to identify the control that sent the event (through the sender parameter) and retrieve any other information that may be associated with the event (through the e parameter). The += operator is used to quickly add information to the end of the label, without replacing the existing text. The event handler uses ToString() to convert the decimal value to text so it can be added to the InnerText property. In this particular statement, you don’t need ToString(), because C# is intelligent enough to realize you’re joining together pieces of text. However, this isn’t always the case, so it’s best to be explicit about data-type conversions.

Adding the Currency Converter Code CurrencyConverter.aspx.cs using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; public partial class CurrencyConverter : System.Web.UI.Page { protected void Convert_ServerClick(object sender, EventArgs e) decimal USAmount = Decimal.Parse(US.Value); decimal euroAmount = USAmount * 0.85M; Result.InnerText = USAmount.ToString() + " U.S. dollars = "; Result.InnerText += euroAmount.ToString() + " Euros."; }

Lecture 2 HTML server control (2)

Behind the Scenes with the Currency Converter The process actually unfolds over several steps: The request for the page is sent to the web server. If you’re running a live site, the web server is almost certainly IIS. If you’re running the page in Visual Studio, the request is sent to the built-in test server. The web server determines that the .aspx file extension is registered with ASP.NET and passes it to the ASP.NET worker process. If the file extension belonged to another service (as it would for .asp or .html files), ASP.NET would never get involved. If this is the first time a page in this application has been requested, ASP.NET automatically creates the application domain. It also compiles all the web page code for optimum performance, and caches the compiled files in the directory c:\Windows\ Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files. If this task has already been performed, ASP.NET will reuse the compiled version of the page.

Behind the Scenes with the Currency Converter The process actually unfolds over several steps: The compiled CurrencyConverter.aspx page acts like a miniature program. It starts firing events (most notably, the Page.Load event). However, you haven’t created an event handler for that event, so no code runs. At this stage, everything is working together as a set of in-memory .NET objects. When the code is finished, ASP.NET asks every control in the web page to render itself into the corresponding HTML markup. The final page is sent to the user, and the application ends. Note: When you click a button on the page, the entire process repeats itself. However, in step 4 the ServerClick event fires for HtmlInputButton right after the Page.Load event, and your code runs.

Error Handling CurrencyConverter.aspx.cs protected void Convert_ServerClick(object sender, EventArgs e) { decimal USAmount; // Attempt the conversion. bool success = Decimal.TryParse(US.Value, out amount); // Check if it succeeded. if (success) { // The conversion succeeded. decimal euroAmount = USAmount * 0.85M; Result.InnerText = USAmount.ToString() + " U.S. dollars = "; Result.InnerText += euroAmount.ToString() + " Euros."; } else { // The conversion failed. Result.InnerText = "The number you typed in was not in the " + "correct format. Use only numbers."; }

Storing Information in the List <form runat="server"> <div> convert: <input type="text" id="US" runat="server"/> U.S. dollar to Euros. <select ID="Currency" runat="server"/> <br/><br/> <input type="submit" value="OK" id="convert" runat="server" OnServerClick="Convert_ServerClick" /> <div runat="server" ID="Result" >…</div> </div> </form>

Storing Information in the List protected void Page_Load(Object sender, EventArgs e) { if (this.IsPostBack == false) Currency.Items.Add(new ListItem("Euros", "0.85")); Currency.Items.Add(new ListItem("Japanese Yen", "110.33")); Currency.Items.Add(new ListItem("Canadian Dollars", "1.2")); } protected void Convert_ServerClick(object sender, EventArgs e) { decimal amount = Decimal.Parse(US.Value); // Retrieve the selected ListItem object by its index number. ListItem item = Currency.Items[Currency.SelectedIndex]; decimal newAmount = amount * Decimal.Parse(item.Value); Result.InnerText = amount.ToString() + " U.S. dollars = "; Result.InnerText += newAmount.ToString() + " " + item.Text; }

Setting Styles protected void Convert_ServerClick(object sender, EventArgs e) { decimal amount = Decimal.Parse(US.Value); if (amount <= 0) Result.Style["color"] = "Red"; Result.InnerText = "Specify a positive number"; } else Result.Style["color"] = "Black"; // Retrieve the selected ListItem object by its index number. ListItem item = Currency.Items[Currency.SelectedIndex]; decimal newAmount = amount * Decimal.Parse(item.Value); Result.InnerText = amount.ToString() + " U.S. dollars = "; Result.InnerText += newAmount.ToString() + " " + item.Text;

Lecture 3 HTML server control (3) A Deeper Look at HTML Control Classes

HTML control inheritance

HTML Control Events The ServerClick is simply a click that’s processed on the server side. It’s provided by most button controls, and it allows your code to take immediate action. The ServerChange event responds when a change has been made to a text or selection control. This event isn’t as useful as it appears because it doesn’t occur until the page is posted back (for example, after the user clicks a submit button). At this point, the ServerChange event occurs for all changed controls, followed by the appropriate ServerClick. The Page.Load event is the first to fire. Event Controls That Provide It ServerClick HtmlAnchor, HtmlButton, HtmlInputButton, HtmlInputImage, HtmlInputReset ServerChange HtmlInputText, HtmlInputCheckBox, HtmlInputRadioButton, HtmlInputHidden, HtmlSelect, HtmlTextArea

The Html Control Base Class Property Description Attributes Provides a collection of all the attributes that are set in the control tag, and their values. Controls Provides a collection of all the controls contained inside the current control. (For example, a <div> server control could contain an <input> server control). Disabled Disables the control when set to true, thereby ensuring that the user cannot interact with it, and its events will not be fired. EnableViewState Disables the automatic state management for this control when set to false. Page Provides a reference to the web page that contains this control Parent Provides a reference to the control that contains this control. Style Provides a collection of CSS style properties TagName Indicates the name of the underlying HTML element Visible Hides the control when set to false

The Html Container Control Class Property Description InnerHtml The HTML content between the opening and closing tags of the control. Special characters that are set through this property will not be converted to the equivalent HTML entities. This means you can use this property to apply formatting with nested tags such as <b>, <i>, and <h1>. InnerText The text content between the opening and closing tags of the control. Special characters will be automatically converted to HTML entities and displayed like text (for example, the less-than character (<) in the web page). This means you can’t use HTML tags to apply additional formatting with this property. The simple currency converter page uses the InnerText property to enter results into a <div> tag.

The Page Class Property Description IsPostBack This Boolean property indicates whether this is the first time the page is being run (false) or whether the page is being resubmitted in response to a control event, typically with stored view state information (true). You’ll usually check this property in the Page.Load event handler to ensure that your initial web page initialization is only performed once. EnableViewState When set to false, it ensures that no controls will maintain state information. Application Holds information that’s shared between all users in your website Session Holds information for a single user, so it can be used in different pages Cache Store objects that are time-consuming to create so they can be reused in other pages or for other clients. Request contains information about the current web request. For example, get information about the user’s browser Response Represents the response ASP.NET will send to the user’s browser. For example, it allows you to redirect the user to a different web page Server Allows you to perform a few miscellaneous tasks. For example, it allows you to encode text so that it’s safe to place it in a URL or in the HTML markup of your page. User If the user has been authenticated, this property will be initialized with user information.

Sending the User to a New Page There are several ways to transfer a user from one page to another: Use an ordinary anchor element, which turns a portion of text into a hyperlink. Send the user to a new page using code To perform redirection in code, you first need a control that causes the page to be posted back. When the page is posted back and your event handler runs: You can use the HttpResponse.Redirect() method to send the user to the new page. You can use the HttpResponse.Transfer() method to send the user to the new page. Click <a href="newpage.aspx">here</a> to go to newpage.aspx. Response.Redirect("newpage.aspx"); Response.Redirect("http://www.prosetech.com"); Server.Transfer("newpage.aspx"); Server.Transfer("http://www.prosetech.com");

References Beginning, A. S. P. (2007). .NET 3.5 in C# 2008: From Novice to Professional , M. MacDonald, Apress. https://www.w3schools.com/

The End