displaying random pictures on webpage via Random generator RRS feed

  • Question

  • User-2116945077 posted

    Hey there

    Basically what I want is this: each time a certain page load/reloads, I want a new picture to be displayed on my webpage.   I've done this once before, but it was on a normal Windows form that has an image box, but on a webpage that doesn't have an image box control....... I'm left with a huge question mark

    Creating the random generator and the array are easy:

     Random r = new Random();
    Image[] decorations = new Image[4];
    decorations[0] = Image.FromFile("randompics/one.jpg");
    decorations[1] = Image.FromFile("randompics/two.jpg");
    decorations[2] = Image.FromFile("randompics/three.jpg");
    decorations[3] = Image.FromFile("randompics/four.jpg");
    int num = r.Next(1, 4); 

    But then I get this error:   'System.Web.UI.WebControls.Image' does not contain a definition for 'FromFile' 

    So I've tried adding the following:

    Random r = new Random();
    System.Drawing.Image[] decorations = new System.Drawing.Image[4];
    decorations[0] = System.Drawing.Image.FromFile("randompics/one.jpg");
    decorations[1] = System.Drawing.Image.FromFile("randompics/two.jpg");
    decorations[2] = System.Drawing.Image.FromFile("randompics/three.jpg");
    decorations[3] = System.Drawing.Image.FromFile("randompics/four.jpg");
            int num = r.Next(1, 4);
            for (int i = 0; i != decorations.Length; i++)
            {//nb.  imagetag is the id of the image-placeholder on the aspx side of the project
                imagetag.Image = decorations[i];

    I get the error :  Error 1 'System.Web.UI.WebControls.Image' does not contain a definition for 'Image' and no extension method 'Image' accepting a first argument of type 'System.Web.UI.WebControls.Image' could be found (are you missing a using directive or an assembly reference?)

    and when I add the "System.Drawing", I get more errors.

    Can someone please help mecry?

    Anxiously hoping for help


    Sunday, May 13, 2018 2:32 PM


All replies