Sunday 16 May 2010

Validation

Below "App_Code", select the Class page, i.e. "Product.cs".

Enter the following code into a "Products" class to validate the Product Name so you must begin with an Upper Case letter:

public partial class Product
{
partial void OnProductNameChanging(string value)
{
if (char.IsLower(value[0]))
{
throw new ValidationException("Product name must start with an upper case letter");
}
}

3. Enter the code below into an "Orders" class to validate the Quantity so that it must be greater than 5:

public partial class Order_Detail
{
partial void OnQuantityChanging(short value)
{
if (value < 5){throw new ValidationException("Order quantity must be greater than 5");
}
}
}

No comments:

Post a Comment