Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
28 views

Lesson 1

Uploaded by

hrithikanair2003
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Lesson 1

Uploaded by

hrithikanair2003
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 36

ASP .

NET

1 Introduction to ASP.NET

By Hajrah Jahan

Office: No. 45, 3rd Floor, Block B

Mob: 055-1062252
What is .NET

● A powerful and versatile framework developed by Microsoft.


● A programming model, comprehensive software infrastructure, & various
services to build robust desktop, web, mobile, gaming consoles, & IoT device
applications.
● Supports multiple languages (C#, Visual Basic, and F#) within the same
framework.

Key Features of .NET:

● Cross-Platform Development
● Language Interoperability
● Unified Framework
Components of .Net Framework - What you can use?

Common Language Runtime or CLR

● Performs memory management, exception handling, debugging, security

checking, thread execution, code execution, code safety, verification, and

compilation.

● The code that is directly managed by the CLR is called the managed code.

● When the managed code is compiled, the compiler converts the source code into

a CPU independent intermediate language (IL) code.


Components of .Net Framework - What you can use?

.Net Framework Class Library

● It contains a huge library of reusable types, classes, interfaces, structures, and


enumerated values.

Common Language Specification

● Contains the specifications for the .Net supported languages and


implementation of language integration.

Common Type System

● Provides guidelines for declaring, using, and managing types at runtime, and
cross-language communication.
Components of .Net Framework - What you can use?

Metadata

● Metadata is the binary information describing the program, which is either stored
in a portable executable file (PE) or in the memory.

Assemblies

● A logical unit consisting of the assembly manifest, type metadata, IL code, and a
set of resources like image files.

Windows Forms

● The graphical representation of any window displayed in the application.


Components of .Net Framework - What you can do?

ASP.NET

● A web development model technology on the .Net framework, made of an


object-oriented hierarchy, and containing all web-related functionalities.

ASP.NET AJAX

● An extension of ASP.NET for AJAX functionality containing components to update


data on a webapp without a complete reload of the page.

ADO.NET

● The technology used for working with databases providing access to data
sources like SQL server, OLE DB, XML etc for retrieving, manipulating, and
ASP.NET - Life Cycle - Application Life Cycle

1. User makes a request for accessing resource on a web page.


2. Browser sends request to the web server.
3. A unified pipeline receives the request and the following events take place:
a. An object of class ApplicationManager is created.
b. An object of class HostingEnvironment is created to provide information
regarding the resources.
c. Top level items in the application are compiled.
4. Response & application objects like HttpContext, HttpRequest & HttpResponse
are created and initialized.
5. An instance of the HttpApplication object is created, assigned to the request &
the request is processed by raising different events.
ASP.NET - Life Cycle - Page Life Cycle

● Helps in writing codes for making some specific thing happen at any stage of the
page life cycle.
● Also helps in writing custom controls & initializing them at right time, populate
their properties with view-state data and run control behavior code.

1. Initialization

2. Instantiation of the controls on the page

3. Restoration and maintenance of the state

4. Execution of the event handler codes

5. Page rendering
ASP.NET page stages

1. Page request - When ASP.NET gets a page request, it decides whether to parse
and compile the page, or there would be a cached version of the page;
accordingly the response is sent.
2. Starting of page life cycle - At this stage, the Request and Response objects
are set. If the request is an old request or post back, the IsPostBack property of
the page is set to true. The UICulture property of the page is also set.
3. Page initialization - At this stage, the controls on the page are assigned
unique ID by setting the UniqueID property and the themes are applied. For a
new request, postback data is loaded and the control properties are restored to
the view-state values.
ASP.NET page stages

4. Page load - At this stage, control properties are set using the view state and
control state values.
5. Validation - Validate method of the validation control is called and on its
successful execution, the IsValid property of the page is set to true.
6. Postback event handling - If the request is a postback (old request), the
related event handler is invoked.
7. Page rendering - At this stage, view state for the page and all controls are
saved. The page calls the Render method for each control and the output of
rendering is written to the OutputStream class of the Response property of page.
8. Unload - The rendered page is sent to the client and page properties, such as
Response and Request, are unloaded and all cleanup done.
Examples of Companies Using .NET

Microsoft:

● Microsoft itself uses .NET for many of its applications, including parts of Windows
OS, Azure cloud services, and Microsoft Office Suite.
● Windows OS, Azure cloud services, Microsoft Office applications like Word and
Excel.

Stack Overflow:

● Stack Overflow, one of the largest online developer communities, uses ASP.NET
MVC and .NET technologies.
● Developers use Stack Overflow daily to ask and answer programming-related
Examples of Companies Using .NET

Intuit:

● Intuit, the company behind financial software like QuickBooks and TurboTax, uses
.NET technologies for their applications.
● QuickBooks and TurboTax are widely used financial management and tax
preparation software.

Jet.com:

● Jet.com, an online shopping platform owned by Walmart, was developed using


ASP.NET Core.
● Jet.com is an e-commerce platform allowing customers to purchase a wide range
Examples of Companies Using .NET

GoDaddy:

● GoDaddy, a domain registrar and web hosting company, utilizes .NET


technologies for their customer-facing applications.
● Customers use GoDaddy's services to register domains, build websites, and host
web applications.

The Salvation Army:

● The Salvation Army, a non-profit organization, has developed their volunteer


management system using ASP.NET.
● The system helps in coordinating volunteers, events, and activities for their
ASP.NET - Classroom Activity 1

Topic: Visual Studio Installation, Set-up with New Project

How to go about?

● Microsoft provides a free version of visual studio which also contains SQL Server.

○ Downloaded from https://visualstudio.microsoft.com/downloads/.

● Install from the downloaded file and complete set-up.

● Create a new project type “ASP Web Application (.NET Framework)”


Core sections of an ASP Page

1. Page Directives:
a. Set up the environment for the page
to run.
b. Imports namespaces, loading
assemblies, and registering new
controls with custom tag names and
namespace prefixes.
2. Code Section:
a. Object model based code to control
events and other functions.
3. Page Layout:
a. Provides the UI of the page and
contains the HTML tags, server
controls, text, multimedia, inline CSS
Page Layout - HTML on the Server

● Standard HTML controls enhanced to enable server side processing.

● Converted to a server control by adding

○ The attribute runat="server"

○ An id attribute to make them available for server-side processing.


ASP Controls

TextBox Control:

● Properties: Text, ID, CssClass, Enabled, Visible.


● Methods:
○ Focus() - The cursor will be placed inside the TextBox, ready for user input
○ Clear() - Clears the content of the TextBox control.

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

Button Control:

● Properties: Text, ID, CssClass, Enabled, Visible.


● Methods:
○ Click() - Programmatically simulates a button click event.

<asp:Button ID="Button1" runat="server" Text="Click Me" OnClick="Button1_Click" />


ASP Controls

Label Control:

● Properties: Text, ID, CssClass, ForeColor, Font.

<asp:Label ID="TextBox1" runat="server"></asp:Label>

ListView Control:

● Properties: DataSource, ID, ItemTemplate, InsertItemPosition, EditIndex, DataKeys.


● Methods:
○ DataBind(): Binds the data source to the ListView control.
○ FindControl(): Finds a control inside an item of the ListView by its ID.

<asp:Button ID="Button1" runat="server" Text="Click Me" OnClick="Button1_Click" />


ASP Controls
GridView Control:

● Properties: DataSource, ID, CssClass, AutoGenerateColumns.


● Methods:
○ DataBind() - Binds the data source to the GridView control.

<asp:GridView ID="GridView1" runat="server"></asp:GridView>

DropDownList Control:

● Properties: Items, ID, CssClass, Enabled, Visible.


● Methods:
○ DataBind() - Binds the data source to the DropDownList control.
○ ClearSelection() - Clears the selection in a DropDownList control.

<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>


ASP Controls

CheckBox Control:

● Properties: Text, ID, CssClass, Checked, Enabled, Visible.


● Methods:
○ Toggle() - Programmatically toggles the checked state of the CheckBox control.

<asp:CheckBox ID="CheckBox1" runat="server" Text="Check Me" />

RadioButton Control:

● Properties: Text, ID, CssClass, Checked, Enabled, Visible.


● Methods:
○ Toggle() - Programmatically toggles the checked state of the RadioButton
control.

<asp:RadioButton ID="RadioButton1" runat="server" Text="Select Me" />


ASP Controls

Image Control

● Properties: ImageUrl, ID, CssClass, AlternateText.

<asp:Image ID="Image1" runat="server" ImageUrl="path/to/image.jpg" />

Calendar Control:

● Properties: SelectedDate, ID, CssClass, VisibleDate.


● Methods:
○ NextMonth() - Navigates to the next month in the Calendar control.
○ PreviousMonth() - Navigates to the previous month in the Calendar control.

<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>


ASP Controls

FileUpload Control

● Properties: ID, CssClass, Enabled, Visible.


● Methods: SaveAs() - Saves the contents of the uploaded file to the specified path.
○ PostedFile() - A property of the FileUpload control in ASP.NET. It allows you to
access the uploaded file.

<asp:FileUpload ID="FileUpload1" runat="server" />

LinkButton Control:

● Properties: Text, ID, CssClass, Enabled, Visible.


● Methods: Click() - Programmatically simulates a click event for the LinkButton
control.

<asp:LinkButton ID="LinkButton1" runat="server" Text="Click Me"


ASP Controls

ASP.NET Page directives

ASP.NET directives are instructions to specify optional settings, such as registering a


custom control and page language.

The attributes of the Page directive are:

● EnableSessionState - Determines whether the page participates in session state.


● EnableViewState - Determines whether the server saves the current state of the
server control's view state.
● ErrorPage - URL for redirection if an unhandled page exception occurs.
ASP Controls

ASP.NET Validators
Validation controls validate the user input data to ensure that useless, unauthenticated,
or contradictory data don't get stored.
Basic Properties
● ControlToValidate - Indicates the input control to validate.
● Display - Indicates how the error message is shown.
● EnableClientScript - Indicates whether client side validation will take place.
● Enabled - Enables or disables the validator.
● ErrorMessage - Indicates error string.
● Text - Error text to be shown if validation fails.
● IsValid - Indicates whether the value of the control is valid.
● SetFocusOnError - The focus should switch to the related invalid input control.
● ValidationGroup - The logical group of multiple validators, where this control
belongs.

ASP Controls

ASP.NET Validators

● RequiredFieldValidator - Ensures that the required field is not empty.


ASP Controls

ASP.NET Validators

● RangeValidator - Verifies that the input value falls within a predetermined range.
ASP Controls

ASP.NET Validators

● CompareValidator - Compares a value in one control with a fixed value or a value


in another control.
○ ControlToCompare - It specifies the value of the input control to
compare with.
○ ValueToCompare - It specifies the constant value to compare with.
○ Operator - It specifies the comparison operator, the available values are:
Equal, NotEqual, GreaterThan, GreaterThanEqual, LessThan, LessThanEqual,
and DataTypeCheck.
ASP Controls

ASP.NET Validators

● RegularExpressionValidator- Allows validating the input text by matching against


a pattern of a regular expression.
○ ControlToValidate: Specifies the ID of the control to validate (EmailTextBox in
this case).
○ ErrorMessage: Defines the error message to display if the validation fails.
○ ValidationExpression: Provides the regular expression pattern to validate the
email address format.

Example: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ is a basic regular


expression for validating email addresses. It ensures the address contains a local part
before the '@' symbol, a domain name after the '@' symbol, and a top-level domain with
at least two characters.
ASP Controls

ASP.NET Validators
● RegularExpressionValidator
<asp:TextBox ID="EmailTextBox" runat="server"></asp:TextBox>

<asp:RegularExpressionValidator ID="EmailValidator" runat="server"

ControlToValidate="EmailTextBox"

ErrorMessage="Invalid email address format"

ValidationExpression="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"

Display="Dynamic"

ForeColor="Red" />

<asp:Button ID="SubmitButton" runat="server" Text="Submit" OnClientClick="return


ValidateForm();" />
ASP Controls

ASP.NET Validators

Common regular expression patterns:

● URL:

Pattern: ^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$

Description: Validates a URL, allowing both HTTP and FTP protocols.

● Numeric Value (Integer or Decimal):

Pattern: ^-?\d+(\.\d+)?$

Description: Validates both integer and decimal numbers, allowing negative values.
ASP Controls

ASP.NET Validators

Common regular expression patterns:

● Date (MM/DD/YYYY or MM-DD-YYYY):

Pattern: ^(0[1-9]|1[0-2])[-/](0[1-9]|[12]\d|3[01])[-/]\d{4}$

Description: Validates dates in MM/DD/YYYY or MM-DD-YYYY format.

● Username (Alphanumeric with Underscores):

Pattern: ^[a-zA-Z0-9_]+$

Description: Validates usernames containing only letters, numbers, and underscores.


ASP Controls

ASP.NET Validators

Common regular expression patterns:

● Phone Number (US Format):

Pattern: ^\(\d{3}\) \d{3}-\d{4}$

Description: Validates US phone numbers in (XXX) XXX-XXXX format.

● Username (Alphanumeric with Underscores):

Pattern: ^[a-zA-Z0-9_]+$

Description: Validates usernames containing only letters, numbers, and underscores.


ASP Controls

ASP.NET Validators

Common regular expression patterns:

● Password (At least one uppercase letter, one lowercase letter, one digit, and minimum
length of 8 characters):

Pattern: ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$

Description: Validates passwords containing at least one uppercase letter, one lowercase
letter, one digit, and a minimum length of 8 characters.

● IP Address (IPv4):

Pattern:^(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\
d|1\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)$

Description: Validates IPv4 addresses.


ASP Controls

ASP.NET Validators

● CustomValidator - Allows writing application specific custom validation routines for


both the client side and the server side validation.
ASP Controls

ASP.NET Validators

● ValidationSummary - Does not perform any validation but shows a summary of all
errors in the page.
○ ShowSummary : shows the error messages in specified format.
○ ShowMessageBox : shows the error messages in a separate window.
ASP.NET - Classroom Activity 2

Topic: Start developing a web app to manage Graduation Projects

How to go about?

● Use your knowledge in controls and validations to develop a registration page for
making a graduation project request.
● Make sure you collect appropriate data related requesting approval of a
graduation project idea.

You might also like