Validate Dependent Fields with Custom Validators

In general, validation in an Iron Speed Designer application is done exactly the same as any .NET application.
- Anh Trinh, Software Engineer, Iron Speed, Inc.

October 18, 2006
Iron Speed Designer V4.0

Procedure
Many times, your application will need additional, customized data validation for certain fields or certain types of fields. You might, for example, find it useful to:
  • Validate related fields where values must be specified in one field or the other.

  • Validate dependent fields where the value of one field is dependent on the value of another field.

  • Perform page-level validation.

Iron Speed Designer generates a Validate() method in the RecordControl class. Simply override this method to implement your own custom data validation. The example below validates fields on an Add Orders Page for the Orders table in the Northwind database. This particular code validates the ShipPostalCode and ShipCountry fields to ensure one or the other field is specified.

Add the code below in the AddOrdersPage class, located in:

.NET Framework 1.1:

...\<Application Folder>\Orders\AddOrdersPage.Controls.cs or .vb

.NET Framework 2.0:

...\<Application Folder>\App_Code\Orders\AddOrdersPage.Controls.cs .vb

C#:

public override void Validate()
{
    base.Validate ();
    if (this.ShipPostalCode.Text.Equals("") || this.ShipCountry.Text.Equals(""))
        throw new Exception("Ship Postal Code and Ship Country cannot be blank");
}

Visual Basic .NET:

Public Overrides Sub Validate()
     MyBase.Validate
     If (Me.ShipPostalCode.Text.Equals("") OrElse Me.ShipCountry.Text.Equals("") Then
          Throw New Exception("Ship Postal Code and Ship Country cannot be blank")
     End If
End Sub

Additional Resources
In general, validation in an Iron Speed Designer application is done exactly the same as any .NET application. Here are resources you might find helpful:

How to validate (using a custom validator) a field according to an option selected in a list box:

http://searchvb.techtarget.com/vsnetATEAnswers/0,293820,sid8_gci912327_tax293672,00.html

The above example also shows how to do validation in JavaScript. You can place the JavaScript in the HTML layout page and it will be passed unmodified to the ASPX page generated by Iron Speed Designer.

The following example shows how to create a custom RequiredIfValidator. This might be helpful if you are doing this often.

https://secure.codeproject.com/cs/miscctrl/RequiredIfValidator.asp

The following example shows how to use the RequiredFieldValidator with other validation controls to handle blank entries.

http://support.microsoft.com/default.aspx?scid=kb;en-us;313044

About the Author
Anh Trinh
Software Engineer, Iron Speed, Inc.

Anh is a software engineer at Iron Speed, Inc. He enjoys developing applications with Iron Speed Designer and Microsoft .NET technology.



  Privacy Statement