Add an Image to a Random Choice of a Placeholder

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jrobexe
    New Member
    • Sep 2008
    • 2

    Add an Image to a Random Choice of a Placeholder

    .NET ASP Visual Studio 2005 Visual Basic

    I have a table with eight placeholders: plc1 - plc8.

    The behind code:
    Code:
            Dim p As Integer = New Integer
            Dim plc As PlaceHolder = New PlaceHolder
            Dim ipic As Image = New Image
            ipic.ImageUrl = "Test\face_brian.jpg"
            Dim plcPic(8) As String
            plcPic(0) = "plc1"
            plcPic(1) = "plc2"
            plcPic(2) = "plc3"
            plcPic(3) = "plc4"
            plcPic(4) = "plc5"
            plcPic(5) = "plc6"
            plcPic(6) = "plc7"
            plcPic(7) = "plc8"
            p = (CInt(plcPic.Length - 1) * Rnd() + 1)
            'Dim adrs As String = Convert.ToString(p)
            plc.ID = plcPic(p)
            plc.Controls.Add(ipic)
    A button starts the Subroutine.
    The code runs and the debugger shows the values being populated, but the Image doesn't display! No errors post.

    Why Not? Any help? It's a mystery.
    Last edited by jrobexe; Sep 17 '08, 08:20 PM. Reason: Identify Platform
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    I'm a C# guy, not a VB guy so I may be way off here. But they are both .NET languages so they are supposed to be somewhat transportable at least in their types.

    ipic is of type Image, which in the C# world is not a Control.
    In your line 17 you try to add the Image to the Controls array of the Placeholder.
    So since it is not of the right type you wouldn't see anything.

    In C# the image would be a property of a Control such as
    Picturebox Fred = new Picturebox;
    Image Wilma = new Image;
    Fred.Image = Wilma;

    Is there something similar in your VB world?
    Placeholder.Ima ge = ipic;

    Comment

    • jrobexe
      New Member
      • Sep 2008
      • 2

      #3
      Thanks so much for your response. I was looking at this issue you pointed out. It seems there is no 'Image' Control to be added as you discerned, but an alternative is to search on an 'ID' using FindControl. While I haven't found an organized method to name the images in the source with 'IDs', this may offer a ray of hope. Thanks once again.


      Originally posted by tlhintoq
      I'm a C# guy, not a VB guy so I may be way off here. But they are both .NET languages so they are supposed to be somewhat transportable at least in their types.

      ipic is of type Image, which in the C# world is not a Control.
      In your line 17 you try to add the Image to the Controls array of the Placeholder.
      So since it is not of the right type you wouldn't see anything.

      In C# the image would be a property of a Control such as
      Picturebox Fred = new Picturebox;
      Image Wilma = new Image;
      Fred.Image = Wilma;

      Is there something similar in your VB world?
      Placeholder.Ima ge = ipic;

      Comment

      Working...