ProMesh.NET Quick Walkthrough - Part 5 - Form Handling

Handling forms is one of the most important features of any web application framework. ProMesh.NET handles this quite a bit differently than most other frameworks, but we believe it is very elegant and powerful.

We'll show the basic by presenting a small example of a form to edit an employee record:

public class EditEmployee : PageController
   public class Employee
       public string Name;
       public decimal Salary;

   public class EmployeeForm : WebForm
       private Employee _employee;

       public string Name;

       public decimal Salary;

       public EmployeeForm(Employee employee)
            _employee = employee;
       // Called when first showing the form
       public override void OnFill()
           Name = _employee.Name;
           Salary = _employee.Salary;

       // Called when the form was posted and all fields are valid
       public override void OnPost()
           _employee.Name = Name;
           _employee.Salary = Salary;

   public void Run(int id)
        Employee employee = new Employee(id);

        EmployeeForm form = new EmployeeForm(employee);


        if (form.Validated)

<form method="post" action="$[_SELF_]">
<label>Name</label> $[[Name]]
<label>Salary></label> $[[Salary]]
<input type="submit" name="btnSave" value="Save" />

The $[[Name]] and $[[Salary]] tags are replaced by text boxes. When posting the form, the input is validated according to the attributes in the form class. If there is a validation error, the values entered in the text boxes will be remembered across postbacks.

Of course you can do more than display text boxes. Other stuff you can do:
  • Use dropdowns, radio buttons, checkboxes or any other control
  • Create your own controls and attributes
  • Use custom validation methods
  • Assign CSS classes
  • ...

The documentation for these features will be added in the next few days.

Next >> Executing other methods

Last edited Aug 27, 2007 at 7:07 PM by activa, version 5


No comments yet.