11 User Controls Beginning ASP.NET 4.5.1 in C# and VB Chapter 8.

Slides:



Advertisements
Similar presentations
Editorial roles Members of a Manila site can be assigned an editorial role if you want to grant them access to write stories or modify the appearance of.
Advertisements

1111 Creating ASPX Controls Programatically Objectives You will be able to Dynamically add controls to a page. Dynamically alter properties of controls.
Chapter 3 – Designing your web pages Dr. Stephanos Mavromoustakos.
Introduction to MVC Adding a View Page NTPCUG Tom Perkins, Ph.D.
11 Getting Started with ASP.NET Beginning ASP.NET 4.0 in C# 2010 Chapters 5 and 6.
User Controls, Master Pages, GridView. Content User Controls Styles, Themes, Master Pages Working with Data GridView Muzaffer DOĞAN - Anadolu University2.
11 User Controls II Chapter Objectives You will be able to Create a realistic reusable user control. Use data binding in a user control. Change.
Web Development in Microsoft Visual Studio Slide 2 Lecture Overview Introduce Visual Studio 2013 Create a first ASP.NET application.
St. Louis Day of Dot Net 2011 Building Web Parts for an Office 365 SharePoint Site Becky Bertram Independent SharePoint Consultant SharePoint MVP, MCSD.NET,
1 Web Services Visual C# 2008 Step by Step Chapter 30.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
11 ASP.NET Controls Beginning ASP.NET 4.0 in C# 2010 Chapter 6.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
JavaScript & jQuery the missing manual Chapter 11
DR.JOHN ABRAHAM PROFESSOR UTPA ASP.NET. ACTIVE SERVER PAGES (ASP) Web application development environment Web applications use web browser to display.
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.
INSPIRING CREATIVE AND INNOVATIVE MINDS Module 4: Adding Code to a Microsoft ASP.NET Web Form Implementing Code-Behind Pages Adding Event Procedures to.
E-Commerce: Introduction to Web Development 1 Dr. Lawrence West, Management Dept., University of Central Florida Topics What is a Web.
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
1 Working with Menus and Dialog Boxes. 2 Objectives You will be able to Create and edit menus for Windows Forms applications. Write code to handle menu.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
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.
MIS 3200 – C# (C Sharp)
Internet Technologies and Web Application Web Services With ASP.NET Tutorial: Introduction to.
11 Using ADO.NET II Textbook Chapter Getting Started Last class we started a simple example of using ADO.NET operations to access the Addresses.
1 Project 3: Chomp (Not graded). 2 Project 3 The game of Chomp was described in a Math Trek column in Science News:
Dynamic Dropdown Lists 1. Objectives You will be able to Use Dropdown Lists to solicit multiple choice user input in an ASPX web page. Populate a Dropdown.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
WRT235: Writing in Electronic Environments Session 2 Basic XHTML.
1 Getting Started with C++. 2 Objective You will be able to create, compile, and run a very simple C++ program on Windows, using Visual Studio 2008.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
IT533 Lectures ASP.NET AJAX.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
Creating and Editing a Web Page
1 More About HTML Images and Links. 22 Objectives You will be able to Include images in your HTML page. Create links to other pages on your HTML page.
Transportation Agenda 187. Transportation About Web Parts Web parts are reusable “containers” that reside on web pages and interact with lists, libraries.
11 ASP.NET Server Controls Beginning ASP.NET in C# and VB Chapter 4.
1 Getting Started with C++ Part 1 Windows. 2 Objective You will be able to create, compile, and run a very simple C++ program on Windows, using Microsoft.
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.
11 Getting Started with ASP.NET Beginning ASP.NET in C# and VB Chapters 1 and 2.
1111 Creating HTML Programatically Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML.
1 Project 4 Address Lookup. Project 4 Write an ASP.NET app that permits users to retrieve addresses from a potentially large list of addresses. There.
1 Windows Forms II Chapter RadioButton / GroupBox Controls Used to solicit a multiple choice input. Radio buttons work as a group. Selecting one.
1111 Master Pages Beginning ASP.NET in C# and VB Chapter 6.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
Creating a Web Site Creating a new Web site Defining and using folders Creating and editing Web pages Viewing pages in a Web browser.
Beginning ASP.NET in C# and VB Chapter 9
XP New Perspectives on Macromedia Dreamweaver MX 2004 Tutorial 5 1 Adding Shared Site Elements.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
1 Adding a Model. We have created an MVC web app project Added a controller class. Added a view class. Next we will add some classes for managing movies.
© Ms. Masihi.  A Web page contains text and images that convey specific information to viewers.  To create a new web page, open Dreamweaver and select.
Howto: Custom page design Creating your own ASPX page Step-by-step guide.
Building CSS in Visual Studio Slide 2 Introduction Using the different HTML (and other) Visual Studio Editors CSS tools.
1 Using MVC 6. MVC vs. ASP Web Forms Both run under ASP.NET Can coexist In Web Forms, browser requests page. xxx.aspx and xxx.aspx.cs on the server Page.
Creating Consistent Looking Websites
Chapter 1 Getting Started with ASP.NET Objectives Why ASP? To get familiar with our IDE (Integrated Development Environment ), Visual Studio. Understand.
MIS 3200 – C# (C Sharp)
Computing with C# and the .NET Framework
ASP.NET Forms.
Objectives Create a folder in Google Drive.
Chapter 8 User Controls.
Web Development in Microsoft Visual Studio 2013
ASP.NET.
Presentation transcript:

11 User Controls Beginning ASP.NET in C# and VB Chapter 8

2 Objectives You will be able to Create reusable chunks of ASPX code, in the form of user controls. Include user controls in ASPX web pages. Include user controls in master pages. Modify user control content from an enclosing page.

3 What are User Controls? ASP.NET page content packaged for reuse. Replacement for “include” files. Independent, compilable component Includes both.aspx and.aspx.cs style code Actual extensions are.ascx and.ascx.cs Can be added to the web site project and put into an ASPX page like normal.NET controls. Compare to master pages Master pages wrap normal ASPX pages. User controls go inside normal ASPX pages.

4 What are User Controls? User controls cannot have top level tags: Cannot be requested directly by a web browser. Must be embedded in other web pages. User controls have a Control directive at the top of the file instead of a Page directive.

5 The Hello World of User Controls Trivial example illustrates the mechanism. A user control that puts a copyright statement on a page. This user control can be added to any ASPX.NET page to put a copyright statement on the page.

6 The Copyright User Control

7 User Control Demo Create a new C# ASP.NET empty web site called User_Control_Demo. Add C# Web Form Default.aspx Title: User Control Demo

Default.aspx 8 Run it!

Initial App in Chrome 9

10 Add a User Control Add new item to the web site Select C# Web User Control Call it Copyright.ascx

Add new item to the web site 11

Adding a Web User Control 12 Scroll down Set name to Copyright.ascx and click Add.

13 View the Source Note "Control" directive at top of page rather than "Page" directive on aspx pages.

14 Copyright.ascx.cs Note class Copyright. Inherited in Copyright.ascx.

15 Add Own HTML Control Language="C#" AutoEventWireup="true" CodeFile="Copyright.ascx.cs" Inherits="Copyright" %> Copyright © University of South Florida This is our reusable chunk of code. Copyright.ascx To enter the © symbol, hold down the 'Alt' key and key in the numerals 0169.

16 Design View does not appear in design view; only at run time.

17 Adding a User Control to a Page Adding a user control to a page requires: “Register” directive Identifies the user control Tells where to find it Control tag Puts the control on the page Visual Studio will put both of these items into the page for us. Just drag and drop the user control from the Solution Explorer to the design view.

Adding a User Control to a Page 18

Page with User Control 19 Look at Source view.

Default.aspx Source View 20 We could have manually added these tags.

21 The App Running End of Section

A More Advanced User Control A user control can have properties. Accessible in the C# page behind code. Permit code for the containing page to interact with the user control. Example: Let the copyright owner be a property of the Copyright user control. Permit the user control to be used by various web sites with different owners. 22

C# Properties Members of C# classes. Look like variables where used. Writen without parentheses. Act like parameterless methods. Invoke code in the property definition get and set Inside the class definition. Same thing that we have seen for ASPX controls in their Properties panels. 23

Copyright.ascx.cx public partial class Copyright : System.Web.UI.UserControl { private string copyright_owner = ""; protected void Page_Load(object sender, EventArgs e) {} public string Copyright_Owner { get { return copyright_owner; } set { copyright_owner = value;} } 24 Property Definition

Copyright.aspx 25

Default.aspx.cs 26 Set the Copyright_Owner property of the Copyright user control.

App in Chrome 27

Another Property Let’s also make the URL of the link settable from the containing page. 28

Add to Copyright.ascx.cs private string _url = "";... public string URL { get { return url; } set { url = value; } } 29

Default.aspx.cs public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Copyright1.Copyright_Owner = "Rollins Turner"; Copyright1.URL = " } 30

Website in Chrome 31 End of Section

User Control Properties User control properties can be any type. Not just strings. A user control can permit its containing page to pass in objects of any class, as well as built-in types such as string and int. 32

Copyright in a Footer A typical use of a copyright user control is in footers of web pages. Let’s add this control to the footer of the Master Page Demo that we wrote last class. Close this project. Download MasterPageDemo.zip to your desktop from the Downloads area of the class web site _02_11_In_Class/ _02_11_In_Class/ Expand the zip file and open the web site. 33

Download MasterPageDemo 34

Download MasterPageDemo 35

Open the Web Site 36 Drill down to the second level MasterPageDemo folder.

Build and Run 37

Add the User Control to the Web Site 38

Add the User Control to the Web Site 39 Navigate to your User_Control_Demo and select Copyright.ascx Click Add.

MasterPageDemo 40 Copyright.ascx.cs came along with Copyright.ascx.

Look at the website folder 41 The user control files have been copied into the website folder

Copyright.ascx.cs Set default values for the properties: copyright_owner url private string copyright_owner = "University of South Florida"; private string url = " 42

Put the User Control into the Footer 43 In Design view, drag and drop Copyright.ascx from Solution Explorer into the footer. Delete “Footer Goes Here”

User Control in Master Page 44

Register Directive 45

User Control in the Footer 46 Add some space above and below the user control.

MasterPageDemo with Copyright 47