March 4th, 2010
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.
Consider a scenario where you want the user to enter their address only if they select Australia as the country, you also need to validate the address fields. Two ways to approach this are:
- For each address field you need to validate use a CustomValidator control, and in the ClientValidationFunction first check to see if the country is set to Australia and if it’s not then consider any response for this control as valid. The problem with this is you will have to recrete all of the validator functionality in your client validation function, which means more work.
- Use standard validator controls for the address fields, and enable or disable them in javascript. The code you call to enable or disable the validators could be a CustomValidation control on the country field, or a standard javascript call when the user selects a country. If the Page_IsValid variable is set to true then assume that the page has just been loaded and no validation has occured, in this case just set the validator controls enabled property so it will be validated (or not) when the user submits the form.
If Page_IsValid is false then assume the user has tried to submit but failed, in this case we expect validation messages to show / hide as the user changes data on the form – this is the normal ASP.Net behaviour.
Here’s an example:
// The ClientValidationFunction of a custom validator for country
function validateCountry(source, args) {
// We we haven't submitted the form yet
if (Page_IsValid) {
// Turn the postcode validator on / off, but don't validate
requiredFieldValidatorPostcode.enabled = enable;
} else {
// Turn the postcode validator on / off, and immediately validate
ValidatorEnable(requiredFieldValidatorPostcode, enable);
}
// Validate country is not empty
args.IsValid = (args.Value.length > 0);
}
Don’t forget to include server side code to mimic this enabling / disabling of validators. To do this override the Validate() function, enable or disable validators depending on the country selected and call the base.Validate() function.
public override void Validate()
{
// Check if we need to validate the postcode.
bool requireAddress = (dropDownListCountry.Text == "Australia");
requiredFieldValidatorPostcode.Enabled = requireAddress;
// Call the normal validation methods.
base.Validate();
}
protected void customValidatorCountry_ServerValidate(object source, ServerValidateEventArgs args)
{
// Implement the server side custom validation for country.
args.IsValid = (args.Value.Length > 0);
}
February 14th, 2010
This weekend I’ve been having fun moving some recording off the full hard drive of my Topfield Masterpiece and trying to convert them into the formats I want. Below is what I’ve learnt in the process, this is only going to be useful to those using Windows.
Moving data off the PVR
If you want to use your recordings on devices other than your Toppy, you’re going to need to get the recordings off it. Fortunately this is the simplest step. For me there were really two options:
- Use the provided USB link from the Toppy and the official ALTAIR software to download the recordings. For one or two recording this will be fine, although for me it took around 4 hours for a normal sized movie.
- Attach the hard drive to your computer use TopfHD Read-Write to copy the recordings over to your PC hard drive.
WARNING! To do this you will need to open your Topfield up to remove the hard drive, in doing so you will void your warrenty. I wouldn’t recommend doing this unless your Toppy is out of warrenty anyway.
You need to use the TopfHD application to transfer files because Windows won’t recognise the file format of the Toppy hard drive. Be very careful not let Windows modify the disk in any way.
Transferring about 8 recorded shows and 4 movies took under 30 mins, this takes longer to set up but is well worth it if you’re trying to move a bit of data.
Watching / Converting the Recordings
Once you’ve got the recordings on your PC they will be in Topfield’s .rec format, which Windows Media nor Quicktime can recognise. My traditional way of converting these files for buring to a DVD went;
- Use ProjectX to convert to m2v file
- Use TMPGEnc DVD Author to convert to DVD format
- Use Nero to burn to DVD.
If you just want to watch them on your computer I’ve got some great news which took me a while to realise: the .rec files can be played directly by the ever useful VLC Media Player.
If you want to convert them to another format, VLC can help you there too. Use the Media > Convert / Save option to convert it into many different formats. Supposedly it can convert to H264 / mp4 format compatible with iPods, however I had real problems with this, the video would be distorted or the audio would be way out of sync. So, after playing around for a while, I thought I give it a go converting directly form Handbrake which I do most of my iPod video conversions with… and this works great!
In summary,
To convert to DVD: Probably still use ProjectX > TMPGEnc DVD Author > DVD.
To convert to iPod: Use Handbrake.
To watch or convert to other media formats: Use VLC Media Player.
Hope this is useful.
January 11th, 2010
I’m currently studying for the Microsoft® .NET Framework 2.0—Application Development Foundation (70-536) exam, using the Microsoft Press Training Kit and I am appalled at the number of errors, both editorial and technical, in this book. There are whole paragraphs that have been taken out of one chapter and used as a place holder in another chapter then never changed, at one stage I was very confused when the book was talking about two different classes that seemed to do the same thing, only to find that they were the same class, it’s name had just be written wrong in places, arrggg.
The problem I find is when I’m not sure about something in the book, I don’t know whether my understanding is wrong or the book is wrong, so I went hunting for a list of known errors and sure enough, Microsoft already know about them, in fact there are so many they created 4 knowledge base pages for them! When combining these in a Word document it ended up being 90+ pages, that’s really bad.
If you have this book or think about getting it, here are the official list of updates from Microsoft:
MCTS Self-Paced Training Kit (Exam 70-536): Microsoft® .NET Framework 2.0—Application Development Foundation comments and corrections Part 1
MCTS Self-Paced Training Kit (Exam 70-536): Microsoft® .NET Framework 2.0—Application Development Foundation Comments and Corrections Part 2
MCTS Self-Paced Training Kit (Exam 70-536): Microsoft® .NET Framework 2.0—Application Development Foundation Comments and Corrections Part 3
MCTS Self-Paced Training Kit (Exam 70-536): Microsoft® .NET Framework 2.0—Application Development Foundation Comments and Corrections Part 4
Perhaps it’s time to reprint the book?