Monday, May 31, 2010

To Change the Image Randomly On Post Back

use a image control with the name imgRandom and Paste the below scratched code on page Load event

Random rnd = new Random();
switch (rnd.Next(3))
{
case 0:
imgRandom.ImageUrl = “Picture1.gif”;
imgRandom.AlternateText = “Picture 1”;
break;
case 1:
imgRandom.ImageUrl = “Picture2.gif”;
imgRandom.AlternateText = “Picture 2”;
break;
case 2:
imgRandom.ImageUrl = “Picture3.gif”;
imgRandom.AlternateText = “Picture 3”;
break;
}

No comments:

Post a Comment