Developing Web Applications with ASP+, Page 2
While <% %> code blocks provide a powerful way to custom manipulate the text output returned from a ASP+ Page, they do not provide much help in providing a clean HTML programming model. Developers using only <% %> code blocks must custom manage page state between round-trips and custom interpret posted values.
Validation controls are added to a ASP+ Page like other server controls (discussed a little later). There are controls for specific types of validation, such as range checking or pattern matching, plus a RequiredFieldValidator that ensures a user does not skip an entry field.
ASP+ Page developers can optionally check the Page.IsValid property at runtime to determine whether all validation server controls on a page are currently valid. This provides a simple "one line" way to determine whether or not to proceed with business logic. For example, the below sample performs a Page.IsValid check before executing a database lookup on the selected category:
Controls Provide ReusabilityIn addition to (or instead of) using <% %> code blocks to program dynamic content, ASP+ Page developers can now leverage ASP+ Server Controls to program web pages. Server controls are declared within a .aspx file using custom tags that contain a runat="server" attribute value.
The below sample uses four server controls: <form runat=server>, <asp:textbox runat=server>, <asp:dropdownlist runat=server>, and <asp:button runat=server>. At runtime these server controls automatically generate HTML content. Using the four server controls mentioned above.
These server controls automatically maintain any client-entered values between round-trips to the server. This control state is not stored on the server (it is instead stored within a <hidden> form field that is round-tripped between requests). Note also that no client-side script was required on the client.
<%@ Page Language="C#"%>
<form action="intro4.aspx" method="post" runat=server>
<h3> Name: <asp:textbox id="Name" runat="server"/>
Category: <asp:dropdownlist id="Category" runat=server>
<asp:button text="Lookup" runat="server"/>
In addition to standard HTML input controls, ASP+ enables developers to utilize richer custom controls on their pages.
About the author:Richard Leinecker is a noted author and trainer.
Page 2 of 2