Web Controls Dr. Awad Khalil Computer Science & Engineering Department AUC.

Slides:



Advertisements
Similar presentations
© 2011 Delmar, Cengage Learning Chapter 1 Getting Started with Dreamweaver.
Advertisements

Chapter 3 – Web Design Tables & Page Layout
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?
IT533 Lecture ASP.NET Controls. Installations Microsoft® SQL Server® 2008 Express.
Intermediate Level Course. Text Format The text styles, bold, italics, underlining, superscript and subscript, can be easily added to selected text. Text.
© by Pearson Education, Inc. All Rights Reserved.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 3-1 of…
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
1 Chapter 20 — Creating Web Projects Microsoft Visual Basic.NET, Introduction to Programming.
With Alex Conger – President of Webmajik.com FrontPage 2002 Level I (Intro & Training) FrontPage 2002 Level I (Intro & Training)
Designing a Classroom Web Site Using NVU Beginning Level.
2. Introduction to the Visual Studio.NET IDE 2. Introduction to the Visual Studio.NET IDE Ch2 – Deitel’s Book.
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.
9-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
Copyright © Texas Education Agency, All rights reserved. 1 Web Technologies Website Development with Dreamweaver.
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.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
Programming with Microsoft Visual Basic 2012 Chapter 12: Web Applications.
Web Technologies Website Development Trade & Industrial Education
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Introducing Web Controls Outline 29.1 Analyzing the.
IE 411/511: Visual Programming for Industrial Applications
Creating a Web Site to Gather Data and Conduct Research.
ASP.NET Web Application and Development Digital Media Department Unit Credit Value : 4 Essential Learning time : 120 hours Digital.
E-Commerce: Introduction to Web Development 1 Dr. Lawrence West, Management Dept., University of Central Florida Topics What is a Web.
ASP.Net, Web Forms and Web Controls 1 Outline Web Controls Text and Graphics Controls AdRotator Control Validation Controls.
Understanding Web Sites. What is a Web Site A collection of Web pages which you can view on the Internet Contains text, graphics, sound, and video to.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
Website Development with Dreamweaver
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 2 Welcome Application Introducing the Visual Basic 2008 Express Edition IDE.
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.
Microsoft Visual Basic 2008 CHAPTER SEVEN Creating Web Applications.
Session 1 SESSION 1 Working with Dreamweaver 8.0.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
Microsoft Visual Basic 2005 CHAPTER 7 Creating Web Applications.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
Introduction to ASP.NET T.Ahlam Algharasi. The Visual Studio IDE Start page 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.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
1 Chapter 12 – Web Applications 12.1 Programming for the Web, Part I 12.2 Programming for the Web, Part II 12.3 Using Databases in Web Programs.
Chapter 5 Quick Links Slide 2 Performance Objectives Understanding Framesets and Frames Creating Framesets and Frames Selecting Framesets and Frames Using.
Chapter 2 – Introduction to the Visual Studio .NET IDE
Week Developing Web Applications 12. Programming for the Web A Web Application Runs on a Web Server and Presents Its Content to the User Across a Network,
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Bookstore Application: Middle Tier Introducing Code-Behind Files, Session State.
BlackBerry Applications using Microsoft Visual Studio and Database Handling.
HTML Concepts and Techniques Fifth Edition Chapter 4 Creating Tables in a Web Site.
January 2006Colby College ITS Setting Up Course Pages.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
IT533 Lectures ASP.NET AJAX.
Creating and Editing a Web Page
Chapter 27 Getting “Web-ified” (Web Applications) Clearly Visual Basic: Programming with Visual Basic nd Edition.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Chapter 28. Copyright 2003, Paradigm Publishing Inc. CHAPTER 28 BACKNEXTEND 28-2 LINKS TO OBJECTIVES Table Calculations Table Properties Fields in a Table.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
Creating Web Pages with Links, Images, and Embedded Style Sheets
XP New Perspectives on Macromedia Dreamweaver MX 2004 Tutorial 5 1 Adding Shared Site Elements.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
ASP.NET Forms.
ASP.NET Web Controls.
Chapter 2 – Introduction to the Visual Studio .NET IDE
ASP.NET Web Controls.
Basic XHTML Tables XHTML tables—a frequently used feature that organizes data into rows and columns. Tables are defined with the table element. Table.
Chapter 2 – Introduction to the Visual Studio .NET IDE
ASP.NET.
PART 2.
Web Development Using ASP .NET
Programming with Microsoft Visual Basic 2008 Fourth Edition
Presentation transcript:

Web Controls Dr. Awad Khalil Computer Science & Engineering Department AUC

Commonly Used ASP.NET Objects  An ASP.NET application when compiled, actually defines a class.  The class inherits from class Page, provided by the.NET Framework.  By inheriting from the Page class, the ASP.NET application gains access to several built-in objects that enable programmers to communicate with a Web browser, gather data sent by an HTTP request and distinguish between users.

Web Forms  ASPX files are usually referred to as Web Forms or Web Form Pages because they normally process form input.  Data entered into a form can be sent to the server, processed, then sent back to the client in different format.  The first time a Web form is requested, the entire page is compiled. Later requests are served from the compiled page and do not have to be recompiled.  Technically, any text file with an.aspx extension is an ASP.NET Web Form page.  Any pure HTML page can be given an.aspx extension and run as an ASP.NET page.  Programmers customize Web Forms by adding Web controls, which include labels, text boxes, images, buttons and other GUI components.

Web Controls  Web controls normally have the attribute runat = “ server ” and are included within an ASP.NET Web Form designated by the tag.  There are four types of Web controls: –XHTML server controls Programmable HTML elements run on the server –Web server controls Form-like controls such as drop-down lists and text boxes –Validation controls ( validators ) Required field validator Range validator –User controls Created by programmer

Web Controls

Using Web Controls  The following table shows the most commonly used Web controls in the standard section of the Toolbox. Web ControlDescription LabelDisplays text that the user cannot edit TextBoxGathers user input and displays text ButtonTriggers an event when clicked DropDownListDisplays a drop-down list of choices from which a user can select an item. RadioButtonListGroups radio buttons ImageDisplays images (e.g., GIF and JPG)

Text and Graphics Controls  The following example shows a simple form for gathering user input. This examples uses all the most commonly used Web controls except Label, which we used in the previous example.  All the code of this example was generated by Web Forms Designer in response to actions performed in Design mode.  This example does not contain any functionality – i.e., no action occurs when the user clicks Register. In successive examples, we demonstrate how to add functionality to many of these Web controls.

WebControls.aspx Page Language="C#" AutoEventWireup="true" 4.CodeFile="WebControls.aspx.cs" Inherits="WebControls" 5.EnableSessionState="False" %> 6. 7.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 8." Web Controls Demonstration This is a sample registration form. 18. Please fill in all fields and click Register.

<asp:Image ID="UserInformationImage" runat="server" 21. ImageUrl="~/Images/user.png" EnableViewState="False" /> Please fill out the fields below <asp:Image ID="FirstNameImage" runat="server" 30. ImageUrl="~/Images/fname.png" 31. EnableViewState="False" /> 32. <asp:TextBox ID="FirstNameTextBox" runat="server" 33. EnableViewState="False"> <asp:Image ID="LastNameImage" runat="server" 37. ImageUrl="~/Images/lname.png"

38. EnableViewState="False" /> 39. <asp:TextBox ID="LastNameTextBox" runat="server" 40. EnableViewState="False"> <asp:Image ID=" Image" runat="server" 46. ImageUrl="~/Images/ .png" 47. EnableViewState="False" /> 48. <asp:TextBox ID=" TextBox" runat="server" 49. EnableViewState="False"> <asp:Image ID="PhoneImage" runat="server" 53. ImageUrl="~/Images/phone.png" 54. EnableViewState="False" /> 55. <asp:TextBox ID="PhoneTextBox" runat="server" 56. EnableViewState="False"> 57. Must be in the form (555)

<asp:Image ID="PublicationsImage" runat="server" 63. ImageUrl="~/Images/publications.png" 64. EnableViewState="False" /> Which book would you like information about? <asp:DropDownList ID="BooksDropDownList" runat="server" 71. EnableViewState="False"> 72. Visual Basic 2005 How to Program 3e Visual C# 2005 How to Program 2e Java How to Program 6e 77. C++ How to Program 5e

78. XML How to Program 1e <asp:HyperLink ID="BooksHyperLink" runat="server" 83. NavigateUrl=" Target="_blank" 84. EnableViewState="False"> 85. Click here to view more information about our books <asp:Image ID="OSImage" runat="server" 90. ImageUrl="~/Images/os.png“ EnableViewState="False"/> Which operating system are you using? 94.

<asp:RadioButtonList ID="OperatingSystemRadioButtonList" 97. runat="server" EnableViewState="False"> 98. Windows XP 99. Windows Windows NT 101. Linux 102. Other <asp:Button ID="RegisterButton" runat="server" 107. Text="Register" EnableViewState="False" />

WebControls.aspx  Before discussing the Web controls used in this ASPX file, we explain the XHTML that creates the layout of the page.  The page contains an h3 heading element (line 17), followed by a series of additional XHTML blocks. We place most of the Web controls inside p elements (i.e., paragraph), but we use an XHTML table element (lines 26-60) to organize the Image and TextBox controls in the user information section of the page.  In the previous example, we described how to add heading elements and paragraphs visually without manipulating any XHTML in the ASPX file directly. Web Forms Designer allows you to add a table in a similar manner.

Adding an XHTML Table to a Web Form  To create a table with two rows and two columns in Design mode, select the Insert Table command from the Layout menu. In the Insert Table dialog that appears, make sure the Custom radio button is selected.  In the Layout group box, change the values of the Rows and Columns combo box to 2. by default, the contents of a table cell are aligned vertically in the middle of the cell. We changed the vertical alignment of all cells in the table by clicking the Cell Properties… button, then selecting top from the Vertical align combo box in the resulting dialog. This causes the content of each table cell to align with top of the cell.  Click OK to close the Cell Properties dialog, then click OK to close the Insert Table dialog and create the table. Once a table is created, controls and text can be added to particular cells to create a neatly organized layout.

Setting the Color of Text on a Web Form  Notice that some of the instructions to the user on the form appear in a teal color.  To set the color of a specific piece of text, highlight the text and select Format > Foreground color…. In the Color Picker dialog, click the Named Colors tab and choose a color from the palette shown.  Click OK to apply the color.  Note that the IDE places the colored text in an XHTML span element and applies the color using the span’s style attribute.

Examining Web Controls on a Sample Registration Form  Lines define an Image control, which inserts an image into a Web page. The ImageUrl property (line 21) specifies the location of the image to display in the Image control. To select an image, click the ellipsis next to the ImageUrl property in the Properties window and use the Select Image dialog to browse for the desired image in the project’s Images folder.  When the IDE fills in the ImageUrl property based on your selection, it includes a tilde and forward slash ( ~/ ) at the beginning of the ImageUrl – this indicates that the Images folder is in the root directory of the project (i.e., whose physical path is C:\Inetpub\wwwroot\WebControls ).

Examining Web Controls on a Sample Registration Form  Lines contain the table element created by the steps discussed previously.  Each td element contains an Image control and a TextBox control, which allows you to obtain text from the user and display text to the user. For example, lines define TextBox control used to collect the user’s first name.  Lines define a DropDownList. This control is similar to ComboBox Windows control. When a user clicks the drop-down list, it expands and displays a list from which the user can make a selection.  Each item in the drop-down list is defined by a ListItem element (lines 72-78).

Examining Web Controls on a Sample Registration Form  After dragging a DropDownList control onto a Web Form, you can add items to it using ListItem Collection Editor. This process is similar to customizing a ListBox in a Windows application.  In IDE, you can access the ListItem Collection Editor by clicking the ellipsis next to the Items property of the DropDownList. It can also be accessed using the DropDownList Tasks menu, which is opened by clicking the small arrowhead that appears in the upper-right corner of the control in Design mode. This menu is called a smart tag menu. Visual Studio displays smart tag menus for many ASP.NET controls to facilitate performing common tasks.  Clicking Edit Items… in the DropDownList tasks menu opens the ListItem Collection Editor, which allows you to add ListItem elements to the DropDownList.

Examining Web Controls on a Sample Registration Form  The HyperLink control (lines 82-86) adds a hyperlink to a Web page. The NavigateUrl property (line 83) of this control specifies the resource (i.e., that is requested when a user clicks the hyperlink.  Setting the Target property to _blank specifies that the requested Web page should open in a new browser window. By default, HyperLink controls cause pages to open in the same browser window.  Lines define a RadioButtonList control, which provides a series of radio buttons from which the user can select only one. Like options in a DropDownList, individual radio buttons are defined by ListItem elements. Note that, like the DropDownList Tasks smart tag menu, the RadioButtonList Tasks smart tag menu also provides an Edit Items… link to open the ListItem Collection Editor.

Examining Web Controls on a Sample Registration Form  The final Web control is a Button (lines ).  Like a Button Windows control, a Button Web control represents a button that triggers an action when clicked.  A Button Web control typically maps to an input XHTML element with attribute type set to “ button ”.  As stated earlier, clicking the Register button in this example does not do anything.

Using AdRotator Control  Web pages often contain product or service advertisement, which usually consist of images.  Although Web site authors want to include as many sponsors as possible, Web pages can display only a limited number of advertisements.  To address this problem, ASP.NET provides the AdRotator Web control for displaying advertisements.  Using advertisement data located in XML file, the AdRotator control randomly selects an image to display and generates a hyperlink to the Web page associated with that image.  Browsers that do not support images display alternate text that is specified in the XML document.  If a user clicks the image or substituted text, the browser loads the Web page associated with that image.

Using AdRotator Control  The following example demonstrates the AdRotator Web control.  In this example, the “advertisements” that we rotate are flags of 10 countries. When a user clicks the displayed flag image, the browser is redirected to a Web page containing information about the country that the flag represents. If a user refreshes the browser or requests the page again, one of the eleven flags is again chosen at random and displayed.  The ASPX file of the example contains XHTML text (i.e., the h3 element in line 17) and AdRotator control named countryRotator (lines 19-21).  This page also contains an XmlDataSource control (lines 22-24), which supplies the data to the AdRotator control.  The background attribute of the page’s body element (line 14) is set to display the image background.png, located in the project’s Images folder. To specify this file, click the ellipsis provided next to the Background property of DOCUMENT in the Properties window and use the resulting dialog to browse for background.png.  You do not need to add any code to the code-behind file, because the AdRotator control does “all the work.”

FlagRotator.aspx Page Language="C#" AutoEventWireup="false" 4.CodeFile="Flagrotator.aspx.cs" Inherits="FlagRotator" 5.EnableSessionState="False" %> 6. 7.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 8." Flag Rotator

FlagRotator.aspx AdRotator Example <asp:AdRotator ID="countryRotator" runat="server" 20.DataSourceID="adXmlDataSource" 21.EnableViewState="False" /> 22.<asp:XmlDataSource ID="adXmlDataSource" runat="server" 23.DataFile="~/App_Data/AdRotatorInformation.xml">

FlagRotator.aspx

Connecting Data to an AdRotator Control  An AdRotator control accesses an XML file to determine what advertisement (i.e., flag) image, hyperlink URL and alternate text to display and include in the page.  To connect the AdRotator control to the XML file, we create an XmlDataSource control – one of several ASP.NET data controls (found in the Data section of the ToolBox ) that encapsulate data sources and make such data available for Web controls.  An XmlDataSource references an XML file containing data that will be used in an ASP.NET application.  To build this example, we first add the XML file AdRotatorInformation.xml to the project. Each project in Visual Studio contains an App_Data folder, which is intended to store all the data used by the project.

FlagRotator.aspx  Right click this folder in the Solution Explorer and select Add Existing Item …, then browse for AdRotatorInformation.xml to add it.  After adding the XML file to the project, drag an AdRotator control from the ToolBox to the Web Form. The AdRotator Tasks smart tag menu will open automatically.  From this menu, select from the Choose Data Source drop-down list to start the Data Source Configuration Wizard. Select XML File as the data-source type. This causes the wizard to create an XmlDataSource with the ID specified in the bottom half of the wizard dialog. We set the ID of the control to adXmlDataSource.  Click OK in the Data Source Configuration Wizard dialog.  The Configure Data Source – adXmlDataSource dialog appears next.

FlagRotator.aspx  In this dialog’s Data File section, click Browse… and, in the Select XML File dialog, locate the XML file you added to the App_data folder.  Click OK to exit this dialog, then click OK to exit the Configure Data Source – adXmlDataSource dialog.  After completing these steps, the AdRotator is configured to use the XML file to determine which advertisements to display.

AdRotatorInformation.xml Images/france.png France Information

Images/germany.png Germany Information Images/italy.png Italy Information

Images/spain.png Spain Information Images/latvia.png Latvia Information

Images/peru.png Peru Information Images/senegal.png Senegal Information

Images/sweden.png Sweden Information Images/thailand.png Thailand Information

Images/unitedstates.png United States Information

Examining AdRotatorInformation.xml  XML document AdRotatorInformation.xml – or any XML document used with an AdRotator control – must contain one Advertisements root element (lines 4-94).  Within that element can be several Ad elements (e.g., lines 5-12), each of which provides information about a different advertisement.  Element ImagrUrl (line 6) specifies the path (location) of the advertisement’s image, and element NavigateUrl (lines 7-9) specifies the URL for the Web page that loads when a user clicks the advertisement.  Note that the XML file cannot contain any whitespace before or after the URL in the NavigateUrl element, or the whitespace will be considered part of the URL, and the page will not load properly.

Examining AdRotatorInformation.xml  The AlternateText element (line 10) nested in each Ad element contains text that displays in place of the image when the browser cannot locate or render the image for some reason (i.e., the file is missing, or the browser is not capable of displaying it).  The AlternateText element’s text is also a tooltip that Internet Explorer displays when a user places the mouse pointer over the image.  The impressions element (line 56) specifies how often a particular image appears, relative to the other images. An advertisement that has a higher Impressions value displays more frequently than an advertisement with a lower value. In our example, the advertisements display with equal probability, because the value of each Impressions element is set to 1.