home *** CD-ROM | disk | FTP | other *** search
Wrap
<%@ Register TagPrefix="Acme" TagName="SourceRef" Src="/quickstart/util/SrcRef.aspx"%> <!-- #include virtual="/quickstart/aspplus/include/header.inc" --> <h4>Introducing Web Forms</h4> <p> <!-- #include virtual="/quickstart/aspplus/include/wftoc1.inc" --> <p> <hr> <!--BEGIN SECTION--> <a name="webforms"> <span class="subhead">What is ASP+ Web Forms?</span> <p> The ASP+ Web Forms Page Framework is a scalable NGWS runtime programming model that can be used on the server to dynamically generate web pages. <p> Intended as a logical evolution of ASP (ASP+ provides syntax compatibility with existing pages), the ASP+ Web Forms Framework has been specifically designed to address a number of key deficiencies with the previous model. In particular: <ul> <li>The ability to create and use reusable UI controls that can encapsulate common functionality and reduce the code a page developer has to write. <li>The ability for developers to cleanly structure their page logic in an orderly -- non-ôspaghetti codeö û fashion. <li>The ability for development/authoring tools to provide strong WYSIWYG design support for pages (existing ASP code today is opaque to a tool). </ul> <p> This section of the quickstart provides a high-level code walkthrough of some key ASP+ Web Forms features. Subsequent sections of the quickstart can then be visited to drill down into more specific details. <!--BEGIN SECTION--> <br> <a name="writingforms"> <br> <span class="subhead">Writing Your First Web Form Page</span> <p> ASP+ Web Form Pages are text files with a <b>.aspx</b> filename extension. They can be deployed throughout an IIS virtual root directory tree. When a browser client requests .aspx resources, the ASP+ runtime parses and compiles the target file into a NGWS class. This class can then be used to dynamically process incoming request (note that the .aspx file is only compiled the first time it is accessed -- the compiled type instance is reused across multiple requests). <p> An ASP+ Page can be created simply by taking an existing HTML file and renaming its file extension .aspx (no modification or code is required). For example, the below sample demonstrates a simple HTML page that collects a user's name and category preference, and then performs a form-post back to the originating page when a button is clicked: <p> <Acme:SourceRef RunSample="/quickstart/aspplus/samples/webforms/intro/intro1.aspx" ViewSource="/quickstart/aspplus/samples/webforms/intro/intro1.src" Icon="/quickstart/aspplus/images/intro1.gif" Caption="Intro1.aspx" runat="server" /> <p> <b>Important:</b> Note that nothing really happens yet when you click the "Lookup" button. This is because the .aspx file contains only static HTML (no dynamic content). As such, the same HTML gets sent back to the client on each trip to the page -- which results in the contents of the form fields (the TextBox and DropDownList) getting lost between requests. <!--BEGIN SECTION--> <br> <a name="usingasp"> <br> <span class="subhead">Using ASP <% %> Render Blocks</span> <p> ASP+ Pages provides syntax compatibility with existing ASP Pages. This includes support for <% %> <b>code render blocks</b> that can be intermixed with HTML content within a .aspx file. These code blocks execute in a top-down manner at page render time. <p> The below example demonstrates how <% %> render blocks can be used to loop over a HTML block (increasing the font size each time): <p> <Acme:SourceRef RunSample="/quickstart/aspplus/samples/webforms/intro/intro2.aspx" ViewSource="/quickstart/aspplus/samples/webforms/intro/intro2.src" Icon="/quickstart/aspplus/images/intro2.gif" Caption="Intro2.aspx" runat="server" /> <p> <b>Important:</b> Unlike ASP, the code used within the above <% %> blocks is <i>compiled</i> -- not interpreted using a script engine. This results in improved runtime execution performance. <p> ASP+ Page developers can utilize <% %> code blocks to dynamically modify HTML output much like they can today with ASP. For example, the below sample demonstrates how <% %> code blocks can be used to interpret results posted back from a client. <p> <Acme:SourceRef RunSample="/quickstart/aspplus/samples/webforms/intro/intro3.aspx" ViewSource="/quickstart/aspplus/samples/webforms/intro/intro3.src" Icon="/quickstart/aspplus/images/intro3.gif" Caption="Intro3.aspx" runat="server" /> <p> <b>Important:</b> 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. As shown in the sample above, developers using only <% %> code blocks must custom manage page state between round-trips and custom interpret posted values. <!--BEGIN SECTION--> <br> <a name="serverctrls"> <br> <span class="subhead">Introduction to ASP+ Server Controls</span> <p> In addition to (or instead of) using <% %> code blocks to program dynamic content, ASP+ Page developers can now leverage <b>ASP+ Server Controls</b> to program web pages. Server controls are declared within a .aspx file using custom tags that contain a <b>runat="server"</b> attribute value. <p> 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. <p> <Acme:SourceRef RunSample="/quickstart/aspplus/samples/webforms/intro/intro4.aspx" ViewSource="/quickstart/aspplus/samples/webforms/intro/intro4.src" Icon="/quickstart/aspplus/images/intro4.gif" Caption="Intro4.aspx" runat="server" /> <p> <b>Important:</b> Note that these server controls automatically maintain any client-entered values between round-trips to the server. This control state is <u>not</u> 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. <p> In addition to standard HTML input controls, ASP+ enables developers to utilize richer custom controls on their pages. For example, the below sample demonstrates how the <asp:adrotator> control can be used to dynamically display rotating ads on a page: <p> <Acme:SourceRef RunSample="/quickstart/aspplus/samples/webforms/intro/intro5.aspx" ViewSource="/quickstart/aspplus/samples/webforms/intro/intro5.src" Icon="/quickstart/aspplus/images/intro5.gif" Caption="Intro5.aspx" runat="server" /> <p> <b>Important:</b> A detailed listing of all built-in server controls can be found in the "Web Forms Control Reference" section of this quickstart. <!--BEGIN SECTION--> <br> <a name="handlingevts"> <br> <span class="subhead">Handling Server Control Events</span> <p> Each ASP+ Server Control is capable of exposing an object model containing properties, methods and events. ASP+ developers can utilize this object model to cleanly modify and interact with the page. <p> The below example demonstrates how a ASP+ Page developer can handle the <b>OnClick</b> event from the <asp:button runat=server> control to manipulate the "text" property of the <asp:label runat=server> control. <p> <Acme:SourceRef RunSample="/quickstart/aspplus/samples/webforms/intro/intro6.aspx" ViewSource="/quickstart/aspplus/samples/webforms/intro/intro6.src" Icon="/quickstart/aspplus/images/intro6.gif" Caption="Intro6.aspx" runat="server" /> <p> This simple sample is functionally equivalent to the "Intro3" sample demonstrated earlier in this section. Note, however, how much cleaner and easier the code is with this new server-control based version. <!--BEGIN SECTION--> <br> <a name="customctrls"> <br> <span class="subhead">Using Custom Server Controls</span> <p> ASP+ ships with 45 built-in server controls that can be used out of the box (please review the <a href="webcontrolsref.aspx">Web Forms Controls Reference</a> section for complete details). In addition to the built-in ASP+ controls, developers can also leverage controls developed by third-party vendors. <p> The below sample demonstrates the use of a simple calendar control. The calendar control has been declared within the page using a <acme:calendar runat=server> tag. Note that the <% Register %> directive at the top of the page is responsible for registering the "Acme" XML tag prefix with the "Acme" code namespace of the control implementation. The ASP+ Page Parser will then utilize this namespace to load the calendar control class instance at runtime. <p> <Acme:SourceRef RunSample="/quickstart/aspplus/samples/webforms/intro/intro7.aspx" ViewSource="/quickstart/aspplus/samples/webforms/intro/intro7.src" Icon="/quickstart/aspplus/images/intro7.gif" Caption="Intro7.aspx" runat="server" /> <p> The calendar control in this sample has been designed to work for both "uplevel" and "downlevel" browsers. For uplevel browsers it generates DHTML output. This DHTML output does not require round-trips back to the server when doing day selections and month navigations. For downlevel browsers the control generates standard HTML 3.2. This HTML 3.2 does require round-trips back to the server to handle client-side user interactions. <p> <b>Important:</b> The code a page developer writes is identical regardless of whether an "uplevel" or "downlevel" browser is used to access the page. The calendar control itself encapsulates all of the logic required to handle the two scenarios. <!--BEGIN SECTION--> <br> <a name="listsanddata"> <br> <span class="subhead">Lists, Data, and Databinding</span> <p> ASP+ ships with a built-in set of data grid and list controls. These can be used to provide custom UI driven from queries against a database or other datasource. For example, the below sample demonstrates how a <asp:datagrid runat=server> control can be used to databind book information collected using a SQL database query: <p> <Acme:SourceRef RunSample="/quickstart/aspplus/samples/webforms/intro/intro75.aspx" ViewSource="/quickstart/aspplus/samples/webforms/intro/intro75.src" Icon="/quickstart/aspplus/images/intro75.gif" Caption="Intro7.5.aspx" runat="server" /> <p> The <asp:datagrid runat=server> <b>DataGrid</b> control provides an easy way to quickly display data results using a traditional grid-control UI. ASP+ Developers can alternatively use the <asp:DataList runat=server> <b>DataList</b> control and a custom "ItemTemplate" template to customize data information: <p> <Acme:SourceRef RunSample="/quickstart/aspplus/samples/webforms/intro/intro8.aspx" ViewSource="/quickstart/aspplus/samples/webforms/intro/intro8.src" Icon="/quickstart/aspplus/images/intro8.gif" Caption="Intro8.aspx" runat="server" /> <p> Note that the <asp:datalist runat=server> control enables end-users to exactly control the structure and layout of each item within the list (via the the <b>ItemTemplate</b> template property). The control also automatically handles the two-column wrapping of content (users can control the number of columns using the <b>Repeatcolumn</b> property on the datalist). <p> An alternate view of the <asp:datalist runat=server> control can be seen with the below sample: <p> <Acme:SourceRef RunSample="/quickstart/aspplus/samples/webforms/intro/intro9.aspx" ViewSource="/quickstart/aspplus/samples/webforms/intro/intro9.src" Icon="/quickstart/aspplus/images/intro9.gif" Caption="Intro9.aspx" runat="server" /> <p> Note that the exact same control, datamodel and page user code was used in this example as in the previous. The only difference was that alternative templates were declaratively supplied to the code. <!--BEGIN SECTION--> <br> <a name="formvalidate"> <br> <span class="subhead">Form Validation Controls</span> <p> The ASP+ Web Forms Page framework 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. <p> Validation controls are added to a ASP+ Page like other server controls. There are controls for specific types of validation, such as range checking or pattern matching, plus a <b>RequiredFieldValidator</b> that ensures a user does not skip an entry field. <p> The below example demonstrates how two <asp:requirefieldvalidator runat=server> controls can be used on a page to validate the contents of the <b>TextBox</b> and <b>DropDownList</b> controls: <p> <Acme:SourceRef RunSample="/quickstart/aspplus/samples/webforms/intro/intro10.aspx" ViewSource="/quickstart/aspplus/samples/webforms/intro/intro10.src" Icon="/quickstart/aspplus/images/intro10.gif" Caption="Intro10.aspx" runat="server" /> <p> Note that 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. <p> Note that ASP+ Page developers can optionally check the <b>Page.IsValid</b> property at runtime to determine whether <u>all</u> 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: <p> <Acme:SourceRef RunSample="/quickstart/aspplus/samples/webforms/intro/intro11.aspx" ViewSource="/quickstart/aspplus/samples/webforms/intro/intro11.src" Icon="/quickstart/aspplus/images/intro11.gif" Caption="Intro11.aspx" runat="server" /> <!--BEGIN SECTION--> <br> <a name="codebehind"> <br> <span class="subhead">Code-Behind Web Forms</span> <p> ASP+ supports two methods of authoring dynamic pages. The first is the method you've seen in the above samples -- where the page code is physically declared within the originating .aspx file. An alternative approach -- known as the <b>Code-behind</b> method -- enables the page code to be more cleanly separated from the HTML content into a separate file altogether. <p> The below sample demonstrates the use of the Code-behind method of writing ASP+ Page code: <p> <Acme:SourceRef RunSample="/quickstart/aspplus/samples/webforms/intro/intro12.aspx" ViewSource="/quickstart/aspplus/samples/webforms/intro/intro12.src" Icon="/quickstart/aspplus/images/intro12.gif" Caption="Intro12.aspx" runat="server" /> <p> <!--BEGIN SECTION--> <a name="endofsection"> <h4>Section Summary</h4> <ol> <li> ASP+ Web Forms provides an easy and powerful way to build dynamic Web UI <li> ASP+ Web Form Pages can target any browser client (no script library or cookie requirements) <li> ASP+ Web Form Pages provides syntax compatibility with existing ASP Pages <li> ASP+ Server Controls provide an easy way to encapsulate common functionality <li> ASP+ ships with 45 built-in server controls. Developers can also use controls built by third-parties <li> ASP+ Server Controls are capable of automatically projecting both "uplevel" and "downlevel" HTML <li> ASP+ Templates provide an easy way to customize the look and feel of list server controls <li> ASP+ Validation controls provide an easy way to do declarative client or server data validation </ol> <p> <!-- #include virtual="/quickstart/aspplus/include/footer.inc" -->