Chapter 6. ASP.NET Controls

   

In this chapter

Intrinsic Controls

List Controls

Rich Controls

Validation Controls

ASP.NET comes with a suite of server controls. These aren't COM+ components ; they're controls that are kicked off when a page request is made. They run on the server and generate HTML code that's inserted into the outgoing HTML stream. The browser sees them as HTML, whereas the ASP.NET page and developer see them as controls.

The question of browser compatibility probably has already entered your mind. Don't worry, though; the HTML code the server controls produce is compatible with any browser. And for some of the rich server controls, such as the Calendar and TreeView , this is a great advantage. Creating cross-browser versions of them would take a sizeable effort. You get them free of charge with ASP.NET.

  • Flexibility comes from the capability to set controls' attributes visually. This means that designers who have no programming skills can edit the controls in an ASP.NET page. All they need to do is run Visual Studio, load up the file, go to Design view, and use the Properties windows to easily edit the controls' attributes.

  • Power comes from the capability to run server-side code in response to client-side events. This is possible because the controls run at the server and they generate postback code (code that results from form posts that have a destination of themselves ) for client-side events.

  • Benefits are provided to the developer, principally because controls represent self-describing , reusable logic that can be deployed as a self-contained unit on a host system or application. Controls can encapsulate reusable functionality, thus automating and simplifying common programming tasks .

  • Cleaner code results when controls are used. Because ASP.NET pages encapsulate code in server controls along with event-handling techniques, they enable you to create a more structured design.

  • Faster development results from the capability to reuse previously tested and optimized controls.

ASP.NET server controls fall into four categories: Intrinsic controls, List controls, Rich controls, and Validation controls. This chapter has sections that describe each control category and provide examples.

You can add server controls to your ASP.NET page in two ways: You can type in the code, or you can drag a control from the Toolbox while Visual Studio is in Design mode. The biggest differences between using the ASP.NET server controls and just adding straight HTML code is that the controls need a runat ="server" directive and their names differ from their HTML counterparts: They all have an asp: prefix.

The following code shows how to add an ASP.NET TextBox server control to the code:

 <asp:TextBox runat="server"      id="Example1"      Text="Some text here..."      MaxLength="30" /> 

You can see the same TextBox control in Design mode within the Visual Studio editor in Figure 6.1. It's being designed visually with the Property window.

Figure 6.1. This TextBox control is easily edited in the Properties window.

graphics/06fig01.gif

   


Special Edition Using ASP. NET
Special Edition Using ASP.Net
ISBN: 0789725606
EAN: 2147483647
Year: 2002
Pages: 233

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net