Cover | Table of Contents | Colophon
<html>
<body>
<h1>Hello World</h1>
</body>
</html>
<html>
<body>
<h1>Hello World</h1>
<br/>
<h2>The date and time is <% =Now%>.</h2>
</body>
</html>
<%@ Page Language="VB" %>
<html>
<body>
<h1>Hello World</h1>
<h1>ASP.NET Style</h1>
<h2>Using VB .NET</h2>
<br/>
<h2>The date and time is <% =DateTime.Now( ) %>.</h2>
</body>
</html>
<%@ Page Language="C#" %>
<html>
<body>
<h1>Hello World</h1>
<h1>ASP.NET Style</h1>
<h2>Using C#</h2>
<br/>
<h2>The date and time is <% =DateTime.Now.ToString( ) %>.</h2>
</body>
</html>
if statements, or function or
subroutine calls, may redirect the flow of the program, but
essentially, once program execution begins, it runs its course
unaffected by anything the user or system may do. Prior to the advent
of GUI environments, most computer programs were linear.
if statements, or function or
subroutine calls, may redirect the flow of the program, but
essentially, once program execution begins, it runs its course
unaffected by anything the user or system may do. Prior to the advent
of GUI environments, most computer programs were linear.
runat=server, that
adds server-side processing to all the normal
functionality of an HTML button.
Sub, in C# return
void). The first parameter represents the object
raising the event. The second, called the event
argument
, contains information specific to the
event, if any. For most events, the event argument is of type
EventArgs,
which does not expose any properties. So the general prototype for an
event in Visual Basic is:
Private Sub EventName(ByVal sender As Object, _
ByVal e As EventArgs)
private void EventName (object sender, EventArgs e)
using
statement in C# or an
Imports
statement in VB.NET. For example, the
default Page_Load event handler in
VB.NET inserted by Visual Studio .NET looks like:
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
|
Event name
|
Description
|
|---|---|
|
DataBinding
|
Occurs when control binds to a data source
|
|
Disposed
|
Occurs when control is released from memory
|
|
Error
|
For the page only, occurs when an unhandled exception is thrown
|
|
Init
|
Occurs when the control is initialized
|
|
Load
|
Occurs when the control is loaded to the Page object
|
|
PreRender
|
Occurs when the control is about to be rendered
|
|
Unload
|
Occurs when the control is unloaded from memory
|
sub Page_Load(ByVal Sender as Object, _
ByVal e as EventArgs)
if not IsPostBack then
' Do the expensive operations only the
' first time the page is loaded.
end if
end sub
void Page_Load(Object sender, EventArgs e)
{
if (! IsPostBack)
{
// Do the expensive operations only the
// first time the page is loaded.
}
}
true.
|
Postback
|
Non-postback
|
|---|---|
|
Button
|
CheckBox
|
|
Calendar
|
CheckBoxList
|
|
DataGrid
|
DropDownList
|
|
DataList
|
ListBox
|
|
ImageButton
|
RadioButtonList
|
|
LinkButton
|
RadioButton
|
|
Repeater
|
<% Response.Expires=0 %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft FrontPage 4.0">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>List Log</TITLE>
<STYLE>
BODY,TD, TH {font-family:Verdana;font-size:8pt}
.controls {font-family:Verdana;font-size:8pt}
#owner {color:red}
</STYLE>
</HEAD>
<BODY>
<%
dim DBConn, rs
set DBConn = Server.CreateObject("ADODB.Connection")
DBConn.open "Driver={SQL Server};server=YourServer; uid=sa; pwd=YourPw;
database=northwind;"
set rs = DBConn.Execute("select * from Customers")
%>
<table bgcolor = "lavender">
<tr>
<th>Company Name</th>
<th>Customer ID</th>
<th>Contact</th>
<th>Title</th>
<th>Phone</th>
</tr>
<% while not rs.eof %>
<tr bgColor="lightsteelblue">
<td><% =rs("CompanyName") %></td>
<td><% =rs("CustomerID") %> </td>
<td><%=rs("ContactName") %></td>
<td
<% if rs("ContactTitle") = "Owner" then %>
id = owner
<% end if %>
> <% = rs("ContactTitle") %> </td>
<td><%=rs("Phone") %></td>
</tr>
<%
rs.moveNext
wend
%>
</Table><h1>,
<a>, and <input>
are not processed by the server, but are sent directly to the browser
for display. Standard HTML controls can be exposed to the server and
made available for server-side processing by
turning them into HTML server controls. Server-side processing allows
for data binding, programmatic response to events, and the ability to
use a fully featured and compiled coding language rather than a
scripting language.
runat="server". In
addition, you will probably want to add an
id
attribute, so that contents of the
control can be accessed and controlled programmatically. If you start
with a simple input control:
<input type="text" size="40">
id and runat attributes, as
follows:
<input type="text" id="BookTitle" size="40" runat="server">
<asp:controlType
id="ControlID"
runat="server" />
asp:. ASP
controls offer a more consistent programming model than the analogous
HTML server control. For example, in HTML, the input tag
(<input>) is used for buttons, single-line
text fields, checkboxes, hidden fields, and passwords. For multiline
text fields, you must use the <textarea>
tag. With ASP controls, each different type of functionality
corresponds to a specific control. For example, all text is entered
using the TextBox control; the number of lines is specified using a
property. In fact, for ASP controls in general, all the attributes
correspond to properties of the control.
<%@ Page Language="C#" %>
<html>
<script runat="server">
void btnBookName_Click(Object Source, EventArgs E)
{
lblBookName.Text = txtBookName.Text;
}
</script>
<body>
<form runat="server">
<h1>ASP Controls</h1>
<br/>
<h2>The date and time is <% =DateTime.Now.ToString( ) %>.</h2>
<br/>
<h2>ASP Control</h2>
Book Name:
<asp:TextBox
id="txtBookName"
size="40"
text="Enter book name."
runat="server" />
<br/>
<br/>
<br/>
<asp:Button
id="btnBookName"
text="Book Name"
onClick="btnBookName_Click"
runat="server" /><asp:controlType
id="ControlID"
runat="server" />
asp:.
<%@ Page Language="C#" %>
<script runat="server">
void lblTime_Init(Object Source, EventArgs E)
{
lblTime.Font.Name = "Verdana";
lblTime.Font.Size = 20;
lblTime.Font.Underline = true;
lblTime.Font.Bold = true;
lblTime.Font.Italic = true;
lblTime.Font.Overline = true;
lblTime.Font.Strikeout = true;
lblTime.Text = DateTime.Now.ToString( )
+ ". Font Name: "
+ lblTime.Font.Name;
}
</script>
<html>
<body>
<form runat="server">
<h1>ASP Controls</h1>
<h2>Basics 1</h2>
<asp:label
id="lblTime"
onInit="lblTime_Init"
runat="server" />
</form>
</body>
</html>
<%@ Page Language="C#" %>
<script runat="server">
void lblTime_Init(Object Source, EventArgs E)
{
lblTime.Font.Name = "Verdana";
lblTime.Font.Size = 20;
lblTime.Font.Underline = true;
lblTime.Font.Bold = true;
lblTime.Font.Italic = true;
lblTime.Font.Overline = true;
lblTime.Font.Strikeout = true;
lblTime.Text = DateTime.Now.ToString( )
+ ". Font Name: "
+ lblTime.Font.Name;
}
</script>
<html>
<body>
<form runat="server">
<h1>ASP Controls</h1>
<h2>Basics 1</h2>
<asp:label
id="lblTime"
onInit="lblTime_Init"
runat="server" />
</form>
</body>
</html>
<%@ Page Language="VB" %>
<script runat="server">
Sub lblTime_Init(ByVal Sender as Object, _
ByVal e as EventArgs)
lblTime.Font.Name = "Verdana"
lblTime.Font.Size = new FontUnit(20)
lblTime.Font.Underline = true
lblTime.Font.Bold = true
lblTime.Font.Italic = true
lblTime.Font.Overline = true
lblTime.Font.Strikeout = true
lblTime.Text = DateTime.Now( ) _
& ". Font Name: " _
& lblTime.Font.Name
End Sub
</script>
<html>
<body>
<form runat="server">
<h1>ASP Controls</h1>
<h2>Basics 1</h2>
<asp:label
id="lblTime"
onInit="lblTime_Init"
runat="server" />
</form>
</body>
</html>false.
The text it contains can exceed the length of the control displayed
on the page.
|
Name
|
Type
|
Get
|
Set
|
Values
|
Description
|
|---|---|---|---|---|---|
|
AutoPostBack
|
Boolean
|
x
|
x
|
true, false
|
Determines if automatic
postback to server will occur if user
changes contents of control. If
false, postback to
server will not occur until the page is posted, either by a button or
another control with AutoPostBack set to true.
Default is false.
|
|
Columns
|
Int32
|
x
|
x
|
0, 1, 2, etc. |
ImageURL
NavigateURL
Text
Text value will display as a tool tip. If the
ToolTip property has been set, then the ToolTip text string will
display as a tool tip.
Target