Web Server Programming

22
Web Server Programming User Controls, Master Pages, GridView

description

Web Server Programming. User Controls, Master Pages, GridView. Content. User Controls Styles, Themes, Master Pages Working with Data GridView. User Controls. An efficient way to reuse a block of user interface A key tool for building modular web applications - PowerPoint PPT Presentation

Transcript of Web Server Programming

Page 1: Web Server Programming

Web Server ProgrammingUser Controls, Master Pages, GridView

Page 2: Web Server Programming

ContentUser ControlsStyles, Themes, Master PagesWorking with DataGridView

Muzaffer DOĞAN - Anadolu University 2

Page 3: Web Server Programming

User ControlsAn efficient way to reuse a block of user

interfaceA key tool for building modular web

applicationsThey help you create consistent website

designs and reuse your hardworkIn ASP.NET, extension of user control files are

.ascxThey can use a code-behind file with event-

handling logicMuzaffer DOĞAN - Anadolu University 3

Page 4: Web Server Programming

Differences Between User Controls and Web PagesExtensions (.ascx and .aspx)Beginning directive (<%@ Control %> and

<%@ Page %>)User controls can't be requested directly by a

web browser. Instead, they must be embedded inside other web pages

Muzaffer DOĞAN - Anadolu University 4

Page 5: Web Server Programming

Creating User ControlsIn Visual Studio, use Add New Item

command and select Web User ControlDesign user control like a web page.

Muzaffer DOĞAN - Anadolu University 5

Page 6: Web Server Programming

Embedding a User ControlSimplest way: Drag & drop user control

from Solution Explorer into a web pageHard way: 1) Use Register directive at the

top of the web page:<%@ Register TagPrefix="apress"

TagName="Footer" Src="Footer.ascx" %>2) Call it using the following tag:

<apress:Footer id="Footer1" runat="server" />

Example: Display date and time (will be shown in the class)

Muzaffer DOĞAN - Anadolu University 6

Page 7: Web Server Programming

Integrated User ControlsThere are two types of user controls:

Independent and IntegratedIndependent user controls don't interact with

the pageIntegrated user controls interact with the

web page that hosts themYou can change the behavior or look of an

integrated user controlExample: Displaying time in long date or

short time formats (will be shown in the class)

Muzaffer DOĞAN - Anadolu University 7

Page 8: Web Server Programming

Changing BehaviorCreate a Property in the user control and change

its value by code or by control tag.1) Changing by code:

Footer1.Format = Footer.FooterFormat.LongDate;Note that user control's Page_Load event runs

before the click event of a button in the web page2) Setting initial appearance in the control tag:

<apress:Footer Format="ShortTime" id="Footer1" runat="server" />

Advanced: You can also use events in order to interact between user control and the web form

Muzaffer DOĞAN - Anadolu University 8

Page 9: Web Server Programming

StylesFormatting features of HTML are limited and

inconsistent.The solution is the CSS standard.CSS is supported by all modern browsers.Styles allow you to add borders, set font

details, change colors, add margin space and padding, and so on.

Muzaffer DOĞAN - Anadolu University 9

Page 10: Web Server Programming

Style TypesInline style: Placed directly inside an HTML

tagInternal style sheet: Placed in the <head>

sectionExternal style sheet: Places in a separate

CSS file

For more information about styles and style sheets, visit http://www.w3schools.com/css

Muzaffer DOĞAN - Anadolu University 10

Page 11: Web Server Programming

ThemesCSS rules are limited to a fixed set of style

attributes.CSS rules can't control other aspects of

ASP.NET controls.For example, CheckBoxList control includes

properties that control how it organizes items into rows and columns. They are outside the scope of CSS.

The themes feature fills this gap.Themes are processed by the server.

Muzaffer DOĞAN - Anadolu University 11

Page 12: Web Server Programming

Using ThemesThemes should be placed in the folder

App_ThemesYou need to create at least one skin file in the

App_Themes folderA skin file is a text file with the .skin

extension

For more information, refer to the textbookMuzaffer DOĞAN - Anadolu University 12

Page 13: Web Server Programming

Master PagesMaster pages allow you to define page

templates and reuse them across your website.

Master pages define the page structure and the common ingredients.

Extension of master pages is .master.Master pages can't be viewed by browsers.

Instead, they must be used by other web pages

Muzaffer DOĞAN - Anadolu University 13

Page 14: Web Server Programming

Master Page and Content PageTo add a master page, click Add New Item

and select Master Page.ContentPlaceHolder is the portion of the

master page that a content page can change.While adding web forms into your

application, don't forget to check Select master page box and select the master page you want to use.

You can use ContentPlaceHolders more than one in a master page.

Muzaffer DOĞAN - Anadolu University 14

Page 15: Web Server Programming

Working with DataADO.NET is the technology that .NET

applications use to interact with a database.There are two ways to work with data.

The first way is using the facilities presented by Visual Studio.

The second way is writing everything in the code by hand.

In this class, we'll see only the first way, which is easier than the other.

Muzaffer DOĞAN - Anadolu University 15

Page 16: Web Server Programming

Controls about Data AccessIn Data section of Toolbox of Visual Studio,

there are two types of controls:Controls to display data

GridView, DataList, DetailsView, FormView, ListView, Repeater

Controls to access data SqlDataSource, AccessDataSource,

LinqDataSource, ObjectDataSource, XmlDataSource, SiteMapDataSource

Muzaffer DOĞAN - Anadolu University 16

Page 17: Web Server Programming

Data Access1) Design the database.

You can use SQL Server, Access, XML, Oracle, etc.

2) Place appropriate data source (i.e. AccessDataSource if you are using Access, or SqlDataSource if you are using SQL Server, etc.) into your web page and configure it.

3) Place appropriate display control (GridView, DataList, etc.) and set its DataSource property.

Muzaffer DOĞAN - Anadolu University 17

Page 18: Web Server Programming

Data Source ControlsData source controls (AccessDataSource,

SqlDataSource, etc.) have four commands:SelectCommand to retrieve recordsUpdateCommand to modify existing recordsInsertCommand to add a new recordDeleteCommand to delete existing records

These commands can take parameters from controls, session state, cookies, and query strings.

Muzaffer DOĞAN - Anadolu University 18

Page 19: Web Server Programming

GridView ControlThe GridView is an extremely flexible grid

control that displays a multicolumn data.Each record in your data source becomes a

separate row in the grid.Each field in the record becomes a separate

column in the grid.GridView has automatic paging, sorting,

selecting and editing features.

Muzaffer DOĞAN - Anadolu University 19

Page 20: Web Server Programming

GridView ColumnsGridView can automatically generate its

columns based on the data.You can hide columns, change their order, or

configure some aspect of their display, such as formatting or heading text.

You can display columns as BoundField, ButtonField, CheckBoxField, CommandField, HyperLinkField, ImageField, or TemplateField

Most basic type is BoundField and you can display a field as a text in the specified column. Muzaffer DOĞAN - Anadolu University 20

Page 21: Web Server Programming

.:. .:. Application .:. .:.There will be an application session in the

class demonstrating data access using an Access database and a GridView

If you were absent in the class, get help from one of your friends that attends to the class.

Muzaffer DOĞAN - Anadolu University 21

Page 22: Web Server Programming

ReferencesBeginning ASP.NET 3.5 in C# 2008: From

Novice to ProfessionalVisual Studio

Muzaffer DOĞAN - Anadolu University 22