Amass

Disable specific controls in a collection

June 25th, 2008 Luke

For a recent project, I had to deal with a fair number of controls on a page that all needed to be disabled at once. This is the function that I wrote to do so:

void DisableControls(List types, ControlCollection controls) { foreach(Control control in controls) { if(types.Contains(control.GetType())) { ((WebControl)control).Enabled = false; } } }

Converting a decimal from base 10 to base 62 in C#

June 10th, 2008 Luke

For a recent project, we needed to store as many possible values into 3 characters as we could, based on a numeric ID. So, we created a function that would convert that ID to base 62, which we could then use to increase the number of available combinations that we could store. Here’s the function:

public const string base62digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; public string ToBase62(int input) { int modulo; string sTemp = ""; do { modulo = input % 62; sTemp = base62digits.Substring(modulo + 1, 1) + sTemp; input = input / 62; } while (input != 0); return sTemp; }

It’s been modified from the VB code to do the same thing, which you can find here.