At the most basic level, forms provide the visual interface of your applications. Each form is a combination of programming logic and user interface rendered as an HTML page by the userâs browser. ASP.NET server controls provide the basic building blocks of forms and expose an object model containing properties, methods, and events. Building a basic form in ASP.NET only requires adding some HTML and some server controls to a page and then handling some server control events in the code-behind to modify and interact with the page. These are the basics of forms and are generally well understood even by beginning ASP.NET programmers.
Beyond the basics, though, certain aspects of forms take some getting used to in ASP.NET: in particular, the concept of programming the server and client sides of an application. Forms are inherently client-side because thatâs where they execute and much of their behavior must be handled in the client browser. This sounds simple enough, but getting forms to do your bidding requires you to write server-side code that writes the client-side code to be executed when the page is loaded in the browser. If that isnât enough, client-side code often needs to be written in JavaScript. Add to that the task of managing the nuances of another scripting language, and you begin to feel as though youâre playing 3-D chess.
This chapter provides solutions to many form-related problems you are likely to encounter in using ASP.NET. By the time youâve waded through a recipe or two, the required client- and server-side maneuvers ought to be manageable.
Microsoft has made several aspects of working with forms easier in ASP.NET 2.0. For instance, setting a formâs default button is a common requirement for many web applications. In ASP.NET 1.x and in classic ASP, setting a formâs default button requires you to write custom client-side JavaScript. In ASP.NET 2.0, however, you can use the new DefaultButton
property of the form object, as we explain in this chapterâs first recipe.
Get ASP.NET 2.0 Cookbook, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.