Asppart 2
Asppart 2
Net – Part II
Jim Fawcett
CSE686 – Internet Programming
Spring 2011
References
Architecture
Controls
Data Binding
State Management
Architecture
@Page
– Defines Language and Code-Behind file
@Import Namespaces
– Equivalent to using directives
@Register
– Registers user controls with page. Page will call render on each of
its registered controls.
@Implements
– Declares an interface this page implements
@Reference
– Specifies a page or user control that will be compiled and linked at
run-time
@Assembly
– Links an assembly to the current page during compilation
Plus more – see help documentation
Page Attribures
CodeFile
– Specifies a path to a code-behind file for the page. Used
with Inherits attribute.
Inherits
– Defines a code-behind class for the page to inherit.
AutoEventWireup
– If true, the default, simple event handlers like
Page_Load(…) are wired up automatically.
Debug
– If true, code behind is compiled with debug symbols.
ASP Components
TextBox ListBox
Label DropDownList
HyperLink CheckBoxList
Image RadioButtonList
CheckBox Repeater – HTML template
RadioButton DataList – HTML template
Table – matrix addresses DataGrid – no longer in
Panel toolbox by default, but can
be added
Button
Calendar
Validation Controls
– RequiredField
– RegularExpression
– Range
– Compare
– Custom
Data Related Controls
Example:
DataSet ds = new DataSet();
ds.ReadXML(Server.MapPath(“test.xml”);
ListBox1.DataSource = ds;
ListBox1.DataTextField = “file”; // omit if flat
ListBox1.DataBind();
Data Binding
Types of state
– Application:
Shared across all clients of this application
– Session:
Per client state persistent over page boundaries. Requires
cookies or URL mangling to manage client association.
– Cookie:
Per client state stored on client. Clients can disable
cookies.
– ViewState:
Shared across post requests to the same page. Sent back
and forth with each request.
Application State
In Application Page:
private void Page_Load(object src, EventArgs e)
{
DataSet ds = (DataSet)
(Application[“SharedDataSet”]);
// client interacts with DataSet
}
Session State
In Global.asax:
void Session_Start(object src, EventArgs e)
{
DataSet ds = new DataSet(); // populated by
clients
Session[“myDataSet”] = ds;
}
In Application Page:
private void Page_Load(object src, EventArgs e)
{
DataSet ds = (DataSet)(Session[“myDataSet”]);
// client interacts with DataSet
}
Cookies