Need to perform validation on a model’s property based on some other state of the model? Here’s a way to achieve it using the IValidatableObject interface and data annotations.

In our example project we want to validate the state field is a valid Australian state if the country field is “Australia”.

Conditional validation of state field

Read the rest of this entry »


Need to validate a form field based on the value of another field in ASP.Net? The .Net Framework provides a javascript function to do just that:

ValidatorEnable(val, enable)

This function takes the validator control (val) and a boolean to determine whether it should be enable or disabled. The problem with this function is that it triggers the validator to validate itself immediately, showing any validation error messages before the user has submitted the form, which may not always be want you want.  The alternative is to set the validator’s enabled property to trigger this validator to validate itself when the user submits the form, and by using the Page_IsValid variable you can test whether the user has triggered a validation or not, then use ValidatorEnable function only after the validation has occurred when the user expects to see validation messages. Read the rest of this entry »


Need to generate a pdf programmatically in dot net? You could purchase an HTML to PDF converter and worry about getting the page to format nicely for paper, or you could use the freely available ReportViewer control from Microsoft.

Microsoft offers SQL Server Reporting Services (SSRS) with SQL Server 2005 and later editions to generate and publish reports using the Report Definition Language (RDL), as an alternative to Crystal Reports. SSRS requires a Report Server to publish reports to so they can be useful, however they also offer a ASP.Net or Windows Forms component called the ReportViewer which we can use in our code without the need for any SQL database to generate reports, and these reports can be saved as Excel files, PDF’s or images. Read the rest of this entry »