November 23, 2014
Hot Topics:

Developing Web Applications with ASP+

  • October 17, 2000
  • By Richard Leinecker
  • Send Email »
  • More Articles »

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.

ASP+ Web Forms Page provides a set of validation server controls that provide an easy-to-use but powerful way to check input forms for errors, and if necessary, display messages to the user.

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.

The validation controls have both "uplevel" and "downlevel" client support. Uplevel browsers will perform validation on the client (using javascript and DHTML). Downlevel browsers will perform the validation on the server. The programming model for both scenarios is identical.

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 Reusability

In 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.

<%@ Page Language="C#"%>
<html>
 <head>
  <link rel="stylesheet"href="intro.css">
 </head>

 <body>

  <center>

   <form action="intro4.aspx" method="post" runat=server>

     <h3> Name: <asp:textbox id="Name" runat="server"/>

     Category:  <asp:dropdownlist id="Category" runat=server>
     <asp:listitem>psychology</asp:listitem>
     <asp:listitem>business</asp:listitem>
     <asp:listitem>popular_comp</asp:listitem>

     </asp:dropdownlist>

     <asp:button text="Lookup" runat="server"/>

   </form>

  </center>

 </body>

</html>
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.

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



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Rocket Fuel