Building ASP.NET Applications 2

54
Building ASP.NET Applications 2 Lecture 3,4 T. Ahlam Algharasi 4 th Level

description

Building ASP.NET Applications 2. Lecture 3,4. T. Ahlam Algharasi 4 th Level. GridView Control. Custom Formatting with TemplateField. T.Ahlam Algharasi. GridView Control. GridView Control Bind Data from a table to Gridview Control. Delete all selected fields from Fields Dialog. - PowerPoint PPT Presentation

Transcript of Building ASP.NET Applications 2

Page 1: Building ASP.NET  Applications 2

Building ASP.NET Applications 2Lecture 3,4 T. Ahlam Algharasi

4th Level

Page 2: Building ASP.NET  Applications 2

GridView Control

Custom Formatting with TemplateField

05.2

T.Ahlam Algharasi

Page 3: Building ASP.NET  Applications 2

3

GridView Control

GridView Control1. Bind Data from a table to Gridview Control.2. Delete all selected fields from Fields Dialog.3. Add Template Field to the Gridview control

T.Ahlam Algharasi

Page 4: Building ASP.NET  Applications 2

4

GridView Control

4. Edit Template > item Template

5. Design the layout

T.Ahlam Algharasi

Page 5: Building ASP.NET  Applications 2

5

GridView Control

6. Bind data to controls

To bind date to Label control

Eval(“FieldName”)

Ex : Eval(“title”)

T.Ahlam Algharasi

Page 6: Building ASP.NET  Applications 2

6

GridView Control

To bind date to image control use ImageUrl properties

To bind date to hyperlink control use NavigateUrl properties To link to an image

To link to a page (and sending record id via url)

“Foldername/” & Eval(“FieldName”)

Ex : “product/” & Eval(“Image”)

“Foldername/” &

Eval(“FieldName”)

Ex : “product/” & Eval(“Image”)

“Pagename?no=” &

Eval(“Id_field”)

Ex : “details.aspx?no=” &

Eval(“ID”)

T.Ahlam Algharasi

Page 7: Building ASP.NET  Applications 2

7

GridView Control

GridView Template Editing HeaderTemplate

T.Ahlam Algharasi

Page 8: Building ASP.NET  Applications 2

8

Demo

Example 1 Master-Details using GridView control (Separate Pages)

product.aspx

details.aspx

When a user click on “more” the details of the selected record will open on details page

Page 9: Building ASP.NET  Applications 2

9

Demo

In product.aspx page Bind Data to the Gridview Control Add A hyperlinkField

Set DataNavigateUrlFields , DataNavigateUrlFormate properties

T.Ahlam Algharasi

Page 10: Building ASP.NET  Applications 2

10

Demo

In details.aspx page1. Configure the Data Source and add where clause

Then Click AddT.Ahlam Algharasi

Page 11: Building ASP.NET  Applications 2

11

Demo

In details.aspx page2. Design a specific template

T.Ahlam Algharasi

Page 12: Building ASP.NET  Applications 2

12

DetailsView Control

DetailsView Control Displays the contents as a single record at a time. It can insert, update and delete the record also.

T.Ahlam Algharasi

Page 13: Building ASP.NET  Applications 2

13

DetailsView Control

DetailsView Control Master/Detail ( GridView and DetailsView)

Ex1 : Display records from two tables

Book category Table

Book Details Table

T.Ahlam Algharasi

Page 14: Building ASP.NET  Applications 2

14

DetailsView Control

DetailsView Control1. Bind Data from Category table to Gridview Control2. Bind Data from Book table to DetailsView Control and

specifies where clause

T.Ahlam Algharasi

Page 15: Building ASP.NET  Applications 2

15

DetailsView Control

DetailsView Control Master/Detail ( GridView and DetailsView)

Ex2 : Display records from one table

Book Details Table Record Detail

T.Ahlam Algharasi

Page 16: Building ASP.NET  Applications 2

16

DetailsView Control

DetailsView Control1. Bind Data from Book table to Gridview Control2. Bind Data from Book table to DetailsView Control and

specifies where clause

T.Ahlam Algharasi

Page 17: Building ASP.NET  Applications 2

17

DetailsView Control

DetailsView Control Master-Details

GridView and DetailsView (Separate Pages)

details.aspx

product.aspx

T.Ahlam Algharasi

Page 18: Building ASP.NET  Applications 2

18

DetailsView Control

In product.aspx Page Add A HyperLinkField

Set DataNavigateUrlFields , DataNavigateUrlFormate properties

T.Ahlam Algharasi

Page 19: Building ASP.NET  Applications 2

19

DetailsView Control

In details.aspx Page

T.Ahlam Algharasi

Page 20: Building ASP.NET  Applications 2

20

DataList Control

DataList Control

Displays fields from a data source within table cell which can be

repeated horizontally across the page or vertically down the

page.

The content and layout of list items in DataList is defined using

templates.

T.Ahlam Algharasi

Page 21: Building ASP.NET  Applications 2

21

DataList Control

DataList Control

One of the main advantage of DataList control is it supports

directional rendering (Horizontal/Vertical)

Horizontal

VerticalT.Ahlam Algharasi

Page 22: Building ASP.NET  Applications 2

22

DataList Control

DataList Control

Description Properties

horizontally or vertically RepeatDirection

number of "columns" RepeatColumns

Description Template Name

Template to define how separator

between items

SeparatorTemplat

e

determines the content and layout of

the list header .

HeaderTemplate

determines the content and layout of

the list footer.

FooterTemplate

T.Ahlam Algharasi

Page 23: Building ASP.NET  Applications 2

23

Demo

Example In The First page

Display the category with Datalist Control

T.Ahlam Algharasi

Page 24: Building ASP.NET  Applications 2

24

Demo

In The Second page Display the books with Gridview Control

T.Ahlam Algharasi

Page 25: Building ASP.NET  Applications 2

25

Demo

In The Second page To Bind Data from data source depending on value of category id

do the following

By Catid to display all product of

thee selected category

T.Ahlam Algharasi

Page 26: Building ASP.NET  Applications 2

26

Demo

In The Second page Design a specific template

T.Ahlam Algharasi

Page 27: Building ASP.NET  Applications 2

Form view Control

FormView control Displays the values of a single record from a data sourse

using user-defined templates Allows you to edit , delete, and insert record.

You can also add validation controls while inserting or updating

27

T.Ahlam Algharasi

Page 28: Building ASP.NET  Applications 2

Form view Control

Templates of the FormView Control EditItemTemplate

The template that is used when a record is being edited.

InsertItemTemplate The template that is used when a record is being created.

ItemTemplate The template that is used to render the record to display only.

Note:The major difference between DetailsView and

FormView is, here user need to define the rendering template for each item.

28T.Ahlam Algharasi

Page 29: Building ASP.NET  Applications 2

Difference between ASP.NET Data Controls

29

Multiple Item Display GridView

T.Ahlam Algharasi

Page 30: Building ASP.NET  Applications 2

Difference between ASP.NET Data Controls

30

Multiple Item Display DataList

T.Ahlam Algharasi

Page 31: Building ASP.NET  Applications 2

Difference between ASP.NET Data Controls

Single Item Display DetailsView

31

T.Ahlam Algharasi

Page 32: Building ASP.NET  Applications 2

Difference between ASP.NET Data Controls

32

Single Item Display FormView

T.Ahlam Algharasi

Page 33: Building ASP.NET  Applications 2

Security is one of the most important component of any application.

Security

Page 34: Building ASP.NET  Applications 2

34

Using Authentication in ASP.NET

Authentication is a process of determining how you will verify a client’s identity when the client requests a page.

Authorization is the process of determining which clients have access to the resources within the web application or current directory.

T.Ahlam Algharasi

Page 35: Building ASP.NET  Applications 2

35

Using Authentication in ASP.NET

Requesting a web page that requires authentication

T.Ahlam Algharasi

Page 36: Building ASP.NET  Applications 2

36

Using Authentication in ASP.NET

Authentication is implemented through one of four

possible authentication systems:

Windows authentication

Forms authentication

Passport authentication

No authentication

T.Ahlam Algharasi

Page 37: Building ASP.NET  Applications 2

37

Using Authentication in ASP.NET

1. Windows Authentication The Windows authentication allows us to use the windows

user accounts. Windows authentication in ASP.NET actually relies on IIS to do the authentication. IIS can be configured so that only users on a Windows domain can log in. If a user attempts to access a page and is not authenticated, they'll be shown a dialog box asking them to enter their username and password.

T.Ahlam Algharasi

Page 38: Building ASP.NET  Applications 2

38

Using Authentication in ASP.NET

2. Passport Authentication Passport Authentication provider uses Microsoft's Passport

service to authenticate users. You need to purchase this service in order to use it.

T.Ahlam Algharasi

Page 39: Building ASP.NET  Applications 2

39

Using Authentication in ASP.NET

Form Authentication Forms Authentication uses HTML forms to collect the user

information and than it takes required actions on those HTML collected values.

The advantage of using this type of authentication It allows you to decide how to store user information.

(storing username and password in the Web.Config file, an XML file, or a database table.)

T.Ahlam Algharasi

Page 40: Building ASP.NET  Applications 2

40

Using Authentication in ASP.NET

Enabling Form Authentication To enable basic Forms authentication for an application,

the follow three steps are to be followed: Set the authentication mode for the application by modifying

the authentication section in the application root Web.Config file.

Deny access to anonymous users in one or more directories in the application by modifying the authorization section in the Web.Config files in the appropriate directories.

Create a login page containing a form that enables users to enter their usernames and passwords.

T.Ahlam Algharasi

Page 41: Building ASP.NET  Applications 2

41

Using Authentication in ASP.NET

To perform Form Authentication Secure pages in a separate

subfolder Create a web.config file inside the

subfolder

Create web configuration file in the folder you want to secure it

Create web configuration file in the root directory.

T.Ahlam Algharasi

Page 42: Building ASP.NET  Applications 2

42

Using Authentication in ASP.NET

Web.Config File

Web.config file (Web configuration file) it keeps the

configurations required for the web application.

There are number of important settings that can be

stored in the configuration file.

Database connections

Session States

Error Handling

Security

T.Ahlam Algharasi

Page 43: Building ASP.NET  Applications 2

43

Using Authentication in ASP.NET

Forms Authentication Configuration1. Configure Forms Authentication in Web.Config.

<authentication mode="Forms">

        <forms loginUrl="~/login.aspx“

defaultUrl="~/adminpages/welcome.aspx” />

 </authentication>

 

T.Ahlam Algharasi

Page 44: Building ASP.NET  Applications 2

44

Using Authentication in ASP.NET

Forms Authentication Configuration

Description Property

Indicates the URL that users are redirected to

after signing in from the login page

if there is no RedirectUrl value the default value

is default.aspx.

defaultUrl

The URL of the login page. The default value is

login.aspx.

loginUrl

T.Ahlam Algharasi

Page 45: Building ASP.NET  Applications 2

45

Using Authentication in ASP.NET

Authorization Configuration Configure Authorization in Web.Config (Subfolder). Use an <authorization> element to ensure that only

authenticated users can access secure pages.

<system.web>

<authorization>

<deny users="?"/>

</authorization>

</system.web>

 

T.Ahlam Algharasi

Page 46: Building ASP.NET  Applications 2

46

Using Authentication in ASP.NET

Permissible elements for authorization are Allow Deny.

Each allow or deny element must contain a users attribute.

Description UserName

All users *Anonymous (unauthenticated) users

?

T.Ahlam Algharasi

Page 47: Building ASP.NET  Applications 2

47

Using Authentication in ASP.NET

Creating the Login Page The ASP.NET login controls provide a robust login solution

for ASP.NET Web applications without requiring programming.

By default, login controls integrate with ASP.NET forms authentication to help automate user authentication for a Web site.

T.Ahlam Algharasi

Page 48: Building ASP.NET  Applications 2

48

Using Authentication in ASP.NET

Login Page Control properties

Description Property

Indicates the text to be displayed in the heading of the control.

TitleText

Indicates the label text of the username text box.

UserNameLabelText

Indicates the label text of the password text box.

PasswordLabelText

Indicates the text that is displayed after failure of login attempt.

FailureText

Indicates the initial value in the username text box.

UserName

Indicates the text of the Login button.

LoginButtonText

true/false. Indicates whether to show Remember Me checkbox or not.

DisplayRememberMe

T.Ahlam Algharasi

Page 49: Building ASP.NET  Applications 2

49

Using Authentication in ASP.NET

Login Page Control Styles

Description Property

Indicates the style property of the Remember Me checkbox.

CheckBoxStyle

Indicates the style property of the failure text.

FailureStyle

Indicates the style property of the title text.

TitleTextStyle

Indicates the style property of the Login button.

LoginButtonStyle

Indicates the style property of the TextBox.

TextBoxStyle

Indicates the style property of the labels of text box.

LabelStyle

T.Ahlam Algharasi

Page 50: Building ASP.NET  Applications 2

50

Using Authentication in ASP.NET

Login code

T.Ahlam Algharasi

Page 51: Building ASP.NET  Applications 2

51

Using Authentication in ASP.NET

Login code

T.Ahlam Algharasi

Page 52: Building ASP.NET  Applications 2

52

Using Authentication in ASP.NET

RedirectFromLoginPage(). Method It is called after a successful Forms Authentication login

to redirect to the URL in the DefaultUrl property which is in the Web.config file.

If the second parameter is true it creates an authentication cookie , otherwise it doesn’t create a cookie

<authentication mode="Forms">

        <forms loginUrl="~/login.aspx“

defaultUrl="~/adminpages/welcome.aspx"

/>

 </authentication>

 

Page 53: Building ASP.NET  Applications 2

53

Using Authentication in ASP.NET

RemeberMeSet if "Remember Me" is checked, it stores the UserName in a

cookie. if the "Remember Me" CheckBox is UNchecked, it will

*delete* the cookie that remembers the UserName.

T.Ahlam Algharasi

Page 54: Building ASP.NET  Applications 2

Questions