Escolar Documentos
Profissional Documentos
Cultura Documentos
Desenvolvimento
ASP.NET
Paulo Sousa
Instituto Superior de Engenharia do Porto
Instituto Politcnico do Porto
ndice
z
z
z
z
z
z
z
Plataforma .net
C#
ASP.net
Visual Studio.net
Web forms ASP.net
Validao de formulrios
Manuteno de estado
Plataforma .net
Introduo ao desenvolvimento
ASP.net
Viso .net
.net framework
z
Plataforma de desenvolvimento
Biblioteca de classes
z
z
C++
C#
Perl
Web Services
Python
User Interface
ASP.NET
COM+
(Transactions, Partitions,
Object Pooling)
Win32
IIS
WMI
CLR
.NET Framework Class Library Support
Thread Support
COM Marshaler
Type Checker
Exception Manager
Security Engine
Debugger
MSIL to Native
Compilers
Code
Manager
Class Loader
Garbage
Collection
Caractersticas CLR
z
z
z
z
z
z
z
z
Mquina virtual
z
z
z
z
z
Standard ECMA
Implementaes CLI
z
Microsoft CLR
Mono (Linux)
Rotor (FreeBSD)
Compilao e Execuo
EXE/DLL
EXE/DLL
(MSIL
(MSILand
and
metadata)
metadata)
Compiler
Compiler
Class
Class Loader
Loader
Class
Class
Libraries
Libraries
(MSIL
(MSILand
and
metadata)
metadata)
JIT
JIT Compiler
Compiler
with
with optional
optional
verification
verification
Trusted,
pre-JITed
code only
Managed
Native
Code
Call to an
uncompiled
method
Execution
Execution
Security
Security Checks
Checks
Runtime Engine
Source
Source
Code
Code
Assembly
z
z
z
z
z
z
Aplicao .net
(Vdeo)
CTS
z
z
z
z
CTS (2/2)
Value types
z
z
Reference types
z
z
int sp
String cp
20
ol
Garbage Collection
(Vdeo)
C#
Introduo ao desenvolvimento .net
Introduo
z
z
z
z
Tudo so objectos
Ficheiros com extenso .cs
Declarao e definio de mtodos no mesmo
ficheiro
Tipos de dados
z
z
z
z
z
z
z
z
object
string
sbyte, short, int, long
byte, ushort, uint, ulong
char
float, double, decimal
bool
Estes tipos so alias para os tipos definidos na
framework
z
Classes e namespaces
z
namespace Demo {
public class MyClass {
...
}
}
Mtodos
z
z
z
Passagem de parmetros
z
z
Por valor
Por referncia
z
z
Herana
z
Herana (2/2)
z
Propriedades
z
Operadores
z
Atribuio
z
Relacionais
z
<
<=
>
>=
==
!=
Lgicos
z
&&
||
Aritmticos
z
z
+ - * / %
+= -= *= /=
++
--
Constantes
z
Pr-definidas
z
z
null
true
false
De utilizador
z
Criao de objectos
// definio da classe
public class MyClass { ... }
// definio da varivel
MyClass obj;
// criao do objecto
obj = new MyClass();
Construtores
z
Arrays
z
// declarao do vector
String[] vec;
// criao do vector
vec = new String[10];
// nmero de elementos pode ser dinmico
vec = new String[n];
Ciclos
// repetio n vezes
for (int x = 0; i < vec.Length; i++)
Console.WriteLine(vec[i]);
// repetio condicional
int i = 0;
while (i < vec.Length)
{
Console.WriteLine(vec[i]);
i++;
}
// enumerao (coleces)
foreach (String x in vec)
Console.WriteLine(x);
Condicionais
// teste de deciso
if (i < vec.Length)
Console.WriteLine(vec[i]);
else
Console.WriteLine(Erro!!!);
// teste mltiplo
switch (x)
{
case 1: ...; break;
case 2: ...; goto case 3;
case 3: ...; break;
default: ...; break;
}
Interfaces
z
z
z
Implementao de Interfaces
z
Enumerados
z
Fortemente tipados
z
z
structs
z
Benefcios
z
Classes e estruturas
class CPoint { int x, y; ... }
struct SPoint { int x, y; ... }
SPoint sp = new SPoint(10, 20);
CPoint cp = new CPoint(10, 20);
sp
10
20
cp
CPoint
10
10
delegates
z
z
Comentrios XML
class XmlElement
{
/// <summary>
/// Returns the attribute with the given name and
/// namespace</summary>
/// <param name="name">
/// The name of the attribute </param>
/// <param name="ns">
/// The namespace of the attribute, or null if
/// the attribute has no namespace</param>
/// <return>
/// The attribute value, or null if the attribute
/// does not exist</return>
/// <seealso cref=" ="GetAttr(string)"/>
public string GetAttr(string name, string ns) {
... ...
}
}
ASP.net
Introduo ao desenvolvimento
ASP.net
O que ASP.NET?
z Sucessor
do ASP
z Pginas dinmicas com processamento
no servidor
z
z Independente
da linguagem de
programo
z Independente do browser
z Integrado na framework .net
(Animao)
ASP.net application
ASP.NET Web Server
Clients
Internet
Internet
Web
Web
Services
Services
Output Cache
Web
Forms
Page1.
aspx
Page2.
aspx
XML
Data
Codebehind
pages
global.
asax
Database
Web.
config
machine.
config
Components
Components
.aspx extension
Page attributes
z
z
z
z
@ Page directive
Atributos Body
Atributos Form
Controlos com atributo id
<%@
<%@ Page
Page Language="vb"
Language="vb" Codebehind="WebForm1.aspx.cs"
Codebehind="WebForm1.aspx.cs"
SmartNavigation="true"%>
SmartNavigation="true"%>
<html>
<html>
<body
<body ms_positioning="GridLayout">
ms_positioning="GridLayout">
<form
<form id="Form1"
id="Form1" method="post"
method="post" runat="server">
runat="server">
<asp:Text
<asp:Text id=Text1
id=Text1 />
/>
</form>
</form>
</body>
</body>
</html>
</html>
O que o Code-Behind ?
z
Single file
Separate files
code
<tags>
Form1.aspx
<tags>
code
Form1.aspx
Form1.aspx.cs
Page1.aspx.cs
public class WebForm1
{
private void cmd1_Click()
{
}
}
Mudana de Paradigma
z
JSP/ASP/PHP
z
ASP.NET
z
IDE
z
Soluo multi-projecto
Multi-linguagem
Multiplos tipos de projecto
Debugger
Gerao de cdigo .net
Gerao de cdigo nativo
z
VS.net
Editor/Browser
Toolbox
Server
Explorer
Task List
Object Browser
Solution
Explorer
Properties
Dynamic Help
Create
Createaa
New
NewProject
Project
Create
Createthe
theInterface
Interface
and
andWrite
WriteCode
Code
Test
Testand
and
Debug
Debug
Build
Build
Ficheiros
z
z
z
My
My Documents
Documents
Visual
Visual Studio
Studio
Projects
Projects
Solution
Solution
wwwroot
wwwroot
ProjectA
ProjectA
Solution.sln
ProjectA.vbproj
WebForm1.aspx
WebForm1.aspx.vb
Development Files
Assembly Files
(Code-behind page)
Bin
Bin
Build
ProjectA.dll
Modelo de Objectos
z
Server
z
Page
z
Request
z
Response
z
Objecto Server
z
z
z
z
z
z
MachineName
CreateObject()
Execute()
Transfer()
MapPath()
...
Classe Page
z
z
z
z
Controls
User
FindControl()
...
Objecto Request
z
z
z
z
z
Browser
Files
Form
ServerVariables
...
Objecto Response
z
z
z
z
z
z
z
ContentType
Expires
IsClientConnected
BinaryWrite()
Clear()
Redirect()
...
Runat="server"
z
z
z
z
Funcionalidade intrnseca
Modelo de programao comum
z
<input
<input type="text"
type="text" id="txtName"
id="txtName"
runat="server"
runat="server" />
/>
Existem no namespace
System.Web.UI.WebControls
Sintaxe asp.net
<asp:TextBox
<asp:TextBox id="TextBox1"
id="TextBox1"
runat="server">Text_to_Display
runat="server">Text_to_Display
</asp:TextBox>
</asp:TextBox>
z
HTML gerado
<input
<input name="TextBox1"
name="TextBox1" type="text"
type="text"
value="Text_to_Display"
value="Text_to_Display"
Id="TextBox1"/>
Id="TextBox1"/>
Bandwidth is limited
Page_Load
Page_Load
Change Events
Textbox1_Changed
Textbox1_Changed
Action Events
Button1_Click
Button1_Click
Page_Unload
Page_Unload
Page is disposed
O que so procediemntos de
evento?
z Aces
Script no cliente
z
<SCRIPT language="language">
Internet
.HTM
Pages
Script no servidor
z
z
z
Internet
.ASPX
Pages
(Vdeo)
Tratamento de eventos
z
protected
protected System.Web.UI.WebControls.Button
System.Web.UI.WebControls.Button cmd1;
cmd1;
private
private void
void InitializeComponent()
InitializeComponent()
{{
this.cmd1.Click
this.cmd1.Click +=
+= new
new System.EventHandler(this.cmd1_Click);
System.EventHandler(this.cmd1_Click);
this.Load
this.Load +=
+= new
new System.EventHandler(this.Page_Load);
System.EventHandler(this.Page_Load);
}}
private
private void
void cmd1_Click(object
cmd1_Click(object s,
s, System.EventArgs
System.EventArgs e)
e) {{ }}
Postback
(Vdeo)
Page.IsPostback
z
private
private void
void Page_Load(object
Page_Load(object sender,
sender, System.EventArgs
System.EventArgs e)
e)
{{
if
if (!Page.IsPostBack)
(!Page.IsPostBack)
{{
//
// executes
executes only
only on
on initial
initial page
page load
load
}}
//this
//this code
code executes
executes on
on every
every request
request
}}
View state
z
Tratamento de dados
z
Server.Transfer()
Response.Redirect()
Demo validators
Mais Informao...
z
MSDN Library
z
http://msdn.microsoft.com/vcsharp/
ASP.net
z
http://msdn.microsoft.com/netframework/
C#
z
http://msdn.microsoft.com/library
http://www.asp.net
http://www.dei.isep.ipp.pt/labdotnet/
Mais Informao...
z
Open CLI
z
http://sourceforge.net/projects/ocl
http://www.go-mono.com/
ECMA
z
http://www.ecma-international.org/
Mais Informao...
z
Introduction to C# @ ECMA
z
http://www.ecmainternational.org/activities/Languages/Introdu
ction%20to%20Csharp.pdf
http://www.ecmainternational.org/activities/Languages/ECMA
%20CLI%20Presentation.pdf
Introduo ao
Desenvolvimento
ASP.NET
Paulo Sousa
Instituto Superior de Engenharia do Porto
Instituto Politcnico do Porto