protected void Button1_Click(object sender, EventArgs e)
{
string code = null;
string fcode = null;
int i;
Random randomclass = new Random();
for (i = 0; i < 5; i++)
{
int k = randomclass.Next(1, 35);
code = getcaptcha(k, 1);
fcode = fcode + code;
}
// here i have used the label name lblCaptcha. You can have your own label in your page.
lblCaptcha.Text = fcode;
}
private string getcaptcha(int i, int j)
{
string gcode = “abcdefghikjlmnopqrstuvwxyz123456789″;
string gencode = null;
gencode = gcode.Substring(i, j);
int div = i / 2;
if (div>=1 && div<=10 )
gencode = gencode.ToUpper();
return gencode;
}