Web Controls
Web Controls
cont’d
Stages in IIS
ASP.NET Request
System.Web.HttpApplication
What really happens
when ASP.NET receives
a request for .aspx page?
System.Web.UI.Page
? ASP.NET
Platform
Services
the scene
Rendered
Behind
HTML
2
Illusion at Work
• In ASP.NET application the code works with objects
and runs in a protected environment on the server.
• The client only sees the results once the web page
processing has ended and the program has been
released from memory.
3
Code-Behind Programming
Second type of code model in ASP.NET
4
Part A “User Interface File”
<html>
<body>
<form id="Form" runat="server">
<asp:Label id="lblTest" runat="server" />
</form>
</body>
</html>
5
Part B “Code-Behind File”
Inherits System.Web.UI.Page
End Class
6
Web Form Inheritance
System.Web.UI
namespace
Custom Custom
Generic
Page Class .aspx file
Page Class
Inherited by (.vb/.cs)
Inherited by
creates
Page
Object
7
Building A Currency Converter Application
Other examples
8
Currency Converter Interfaces
9
Improving Currency Converter
10
Problems with ASP
Development with ASP?
1. Heavy use of
Response.Write
2. Spaghetti code (statements
order)
3. Lack of flexibility
(modification)
4. Mixing of content and
formatting
5. Complexity
6. No state management of
User Interface (automatic)
11
Problems with ASP
ASP.NET High Level Model Programmers had to master
HTML for designing dynamic
web pages.
Extensive code changes were
required whenever UI was
Server Side Web Controls modified.
12
Server Controls
2. Web Controls
– Richer object model with more properties, events
– More closer to windows development
– Include advanced controls (e.g. Datagrid)
13
HTML Server Controls
Key features
1. Generate their interface
2. Retain state
3. Fire events
14
HTML Server Control Classes
• System.Web.UI.HtmlControls namespace
• Separate class for each control
• Properties, methods, events
15
Structure of CCA User Interface
HtmlForm
instance
empty
HtmlInputText
HtmlInputButton HtmlGenericControl
instance instance instance
HtmlGenericControl
16
instance
Design View
17
XHTML Source View (.aspx)
18
Code View (.vb)
19
Handler for Page Load Event
20
Event Handler for Convert.ServerClick
21
Event Handler for ShowGraph.ServerClick
22