How WebFu works with forms

WebFu provides utilities to assist in developing forms in an MVP manner. WebFu makes it easy to use DataAnnotations for DRY validation code. WebFu provides model binders for DRY code to transfer values from a page, form data, AJAX, or other models. WebFu provides for full globalization using Resource files in conjunction with DataAnnotations with <WebFu:LabelFor ... /> and <%=Html.LabelFor(m => m.FirstName)%>.

Using ASP.NET Server Controls
When using ASP.NET's built-in controls you can use <WebFu:DataAnnotationValidator ../> server control to apply validation to your forms. These server controls work with the built-in ASP.NET validation system on the server side (ie: Page.IsValid) and the jQuery validate plugin on the client-side using <WebFu:EnableClientValidationControl ../>.
To bind data to the page controls, you can use the WebControlUtilities.ApplyModelToPage() method, which can bind model values to TextBox, DropDownList, ListBox, RadioButton and CheckBox controls. Custom controls can implement the IWFControlValue interface.
See here for an example of a Web Forms page using WebFu server controls for validation:
Validators and model binders can bind to properties on child objects such as Customer.Address.City.
For example:
        <WebFu:DataAnnotationValidatorControl ID="DataAnnotationValidatorControl5"
                                              PropertyName="Address.City" />

Using MVC-style HtmlHelpers
If you are familiar with MVC and wish to use Web Forms much like you would an MVC project, WebFu provides many of the pieces for you.
HtmlHelpers provided by WebFu behave much like the helpers in MVC2. Both strongly-typed helpers <%=Html.TextBoxFor(m => m.FirstName) %> and decoupled helpers <%=Html.TextBoxFor(markupname, name, model, value)%> are provided for all common web forms controls.
User controls can be used as strongly-typed partial views from both AJAX and markup <%=Html.RenderControl("~/Controls/MyUserControl.ascx", MyModel)%>.
The downside to using only HtmlHelpers and controls-as-partial-views is that you must adopt an MVP style of development that does not make use of the ViewState (instead use model binding to keep values between requests) or the event pipeline (use WebFu's webfu.callPage(), webfu.submitForm(), WFPageUtilities.CallJSMethod(), etc.). The codebehind of the Page class acts as the presenter (in MVC it would be analogous to the controller).
An example of this is provided here:
On the plus side, WebFu's MVC-style helpers and utilities can be used side-by-side with server controls to augment AJAX/Web 2.0 functionality on a Web Forms page.

Last edited May 21, 2012 at 9:19 PM by aikeru, version 3


No comments yet.