Académique Documents
Professionnel Documents
Culture Documents
NET
1
ASP.NET Architecture
2
Evolution
3
Revolution
4
Page Compilation
5
ASP.NET Page Compilation
HTTP Request
IIS & PageParser::
GET /foo/foo.aspx
ASP.NET GetCompiledPageInstance
Create foo_aspx
instance
Call
Page::ProcessRequest
HTTP Response
HTTP/1.1 200 OK ...
Content-Type: text/html;
Page::ProcessRequest
Content-Length: 300
calls
<html><body>
Page::RenderControl
...
</body></html>
6
ASP.NET Compilation model
7
System.Web.UI.Page
8
System.Web.UI.Page
// Intrinsics
public HttpRequest Request {get;}
public HttpResponse Response {get;}
public HttpServerUtility Server{get;}
public string MapPath(string virtualPath);
public void Navigate(string url);
// Client information
public ClientTarget ClientTarget {get; set;}
public bool IsUplevel {virtual get;}
public IPrincipal User {get;}
//...
}
9
System.Web.UI.Page
// Events
public event EventHandler Init;
public event EventHandler Load;
public event EventHandler PreRender;
public event EventHandler Unload;
//...
}
10
Sample aspx file customizing Page
12
Sample aspx file with code behind
<html>
<body>
<h2>My test page</h2>
</body>
</html>
13
Sample code-behind file – SamplePage.cs
using System; using System.Web.UI; using System.Collections;
namespace DM.AspDotNet
{
public class MyPage : Page {
private ArrayList m_values = new ArrayList();
protected void Page_Load(Object sender, EventArgs e) {
if (!Page.IsPostBack) {
m_values.Add("v1"); m_values.Add("v2");
m_values.Add("v3"); m_values.Add("v4");
}
}
public void WriteTitle() {
if (IsUplevel) {
Response.Write("<div style=\"width:100%; filter:");
Response.Write("progid:DXImageTransform.");
Response.Write("Microsoft.Wheel(duration=3);\">");
Response.Write("My page array has the following values:</div>");
}
else
Response.Write("<div>My page array has the following values:</div>");
}
public void WriteArray() {
Response.Write("<ul>");
for (int i=0; i<m_values.Count; i++)
Response.Write("<li>" + m_values[i] + "</li>");
Response.Write("</ul>");
14
} } }
ASP.NET Directives
15
ASP.NET Directives
16
@page Directives
Name Description
language Programming language to use for <%
17
Server-side controls
18
Traditional HTML generation
19
Figure 3.1: Traditional ASP page
20
ASP.NET server side controls
21
Figure 3.2: ASP.NET page using server-side controls
<body>
<form runat=server>
<h3>Enter name: <input ID="txtName" type=text runat=server/>
Personality: <select ID="Personality" runat=server>
<option>extraverted</option>
<option>introverted</option>
<option>in-between</option>
</select>
<input type=submit value="Submit"/>
<p>
<% if (IsPostBack) {%>
Hi <%=txtName.Value%>, you selected <%=Personality.Value%>
<% } %>
</p>
</form>
</body>
</html>
22
Figure 3.3: HTML generated by server side controls
<html>
<body>
<form name="ctrl1" method="post" action="ServerSideCtrls.aspx" id="ctrl1">
<input type="hidden"
name="__VIEWSTATE" value="YTB6MTY0MDA4NTc2Ml9fX3g=a7d02a14" />
<h3>Enter name: <input name="txtName" id="txtName"
type="text" value="Joe" />
Personality: <select name="Personality" id="Personality">
<option value="extraverted">extraverted</option>
<option selected value="introverted">introverted</option>
<option value="in-between">in-between</option>
</select>
<input type=submit value="Submit"/>
<p>
Hi Joe, you selected introverted
</p>
</form>
</body>
</html>
23
Server-side events
24
Figure 3.4: Using server-side events
<%@ Page Language="C#" %>
<html>
<head>
<script runat=server>
void WriteGreeting(Object sender, EventArgs E)
{
Greeting.InnerText = "Hi " + txtName.Value + ", you selcted " +
Personality.Value;
}
</script>
</head>
<body>
<form runat=server>
<h3>Enter name: <input ID="txtName" type=text runat=server/>
Personality: <select ID="Personality" runat=server>
<option>extraverted</option>
<option>introverted</option>
<option>in-between</option>
</select>
<input type=button value="Submit"
runat=server OnServerClick="WriteGreeting" />
<div id="Greeting" runat=server />
</form>
</body>
</html>
25
Figure 3.5: HTML generated using server-side events
<html>
<body>
<form name="ctrl2" method="post" action="ServerSideEvents.aspx" id="ctrl2">
<input type="hidden" name="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" value="YTB6..." />
<script language="javascript">
function __doPostBack(eventTarget, eventArgument) {
var theform = document.ctrl2
theform.__EVENTTARGET.value = eventTarget
theform.__EVENTARGUMENT.value = eventArgument
theform.submit()
}
</script>
<h3>Enter name:
<input name="txtName" id="txtName" type="text" value="Joe" />
Personality: <select name="Personality" id="Personality">
<option value="extraverted">extraverted</option>
<option value="introverted">introverted</option>
<option selected value="in-between">in-between</option> </select>
<input name="ctrl7" type="button" value="Submit" /
onclick="javascript:__doPostBack('ctrl7','')">
<div id="Greeting">Hi Joe, you selected in-between</div>
</form></body></html>
26
Controls
27
HtmlControls
28
Figure 3.6: Hierarchy of HtmlControls and the tags they map to
System.Object
System.Web.UI.Control
HtmlControl
HtmlImage <img> HtmlContainerControl
HtmlInputControl HtmlForm <form>
<span>,
HtmlInputFile <input type=file> HtmlGenericControl <div>, ...
HtmlInputHidden <input type=hidden> HtmlSelect <select>
29
WebControls
30
Figure 3.7: Hierarchy of WebControls
System.Object
System.Web.UI.Control
WebControl
AdRotator LinkButton Image
BaseDataList ListControl ImageButton
DataGrid RadioButtonList Label
CheckBoxList BaseValidator
DataList
DropDownList CompareValidator
Button
ListBox CustomValidator
Calendar
Panel RangeValidator
CheckBox
Table RegularExpressionValidator
RadioButton
TableCell RequiredFieldValidator
HyperLink
TableHeaderCell ValidationSummary
TextBox
TableRow
31
Figure 3.9: A sample ASP.NET page written with HtmlControls
<body>
<form runat=server>
<input type=radio runat=server>click me</input><br/>
<input type=checkbox runat=server>check me</input><br/>
<input type=button value="Push me" runat=server /><br/>
<input type=text value="type in me" runat=server /><br/>
<textarea value="type more in me" runat=server /><br/>
<table runat=server>
<tr><td>cell00</td><td>cell01</td></tr>
<tr><td>cell10</td><td>cell11</td></tr>
</table>
</form>
</body>
</html>
32
Figure 3.8: A sample ASP.NET page written with WebControls
<%@ Page Language="C#" %>
<html>
<body>
<form runat=server>
<asp:RadioButton Text="click me" runat=server/><br/>
<asp:CheckBox Text="check me" runat=server/><br/>
<asp:Button Text="Push me" runat=server /><br/>
<asp:TextBox Text="type in me" runat=server /><br/>
<asp:TextBox TextMode=MultiLine rows=3
Text="type more in me" runat=server /><br/>
<asp:Table runat=server>
<asp:TableRow>
<asp:TableCell>cell00</asp:TableCell>
<asp:TableCell>cell01</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>cell10</asp:TableCell>
<asp:TableCell>cell11</asp:TableCell>
</asp:TableRow>
</asp:Table>
</form>
</body>
</html>
33
Summary
34
Questions
35