Generate Random Color Object in C#

This is a handy little snippet if you’re stubbing out a UI and need to initialize color pickers, enjoy!

private Color GetRandomColor()
    Random randomGen = new Random();
    KnownColor[] names = (KnownColor[])Enum.GetValues(typeof(KnownColor));
    KnownColor randomColorName = names[randomGen.Next(names.Length)];
    Color randomColor = Color.FromKnownColor(randomColorName);
    return randomColor;

Source: How to generate random color names in C#

Disable client side validation for fields in Web Forms

Disabling validation for hidden fields with ASP.NET Web Forms is certainly not as easy as doing with with ASP.NET MVC as I have posted about before, but it is totally doable.

You will have to work with the Page.Validators object on the client side. It is a global variable call Page_Validators, it is an array that contains all your validators for the page.

Basically you can cycle through this array and disable validators based on the validators id, you use a javascript function called ValidatorEnable() to enable/disable validators as you hide and show sections of your form.

Here is a code sample:

for (i = 0; i < Page_Validators.length; i++) {
    if (Page_Validators[i].id === "<%= RequiredFieldValidatorOne.ClientID %>") {
        ValidatorEnable(Page_Validators[i], false);
    if (Page_Validators[i].id === "<%= RequiredFieldValidatorTwo.ClientID %>") {
        ValidatorEnable(Page_Validators[i], true);

Hopefully this saves you some time down the line for your more complex ASP.NET Web Forms.

Video file meta data location

Something that can be very frustrating is if your videos for an application are slow loading up. You might be thinking it is a slow server but chances are the meta data for the video file are at the end of the file which means the client must download the entire video before playback can start!

I had this issue recently with an application using FlowPlayer to play tutorial videos.

There is a section on their website about this issue and it was indeed a video converter moving the meta file to the end of the file on me.

A quick fix was to move the meta data back to the start of the video using QTIndexSwapper.