Loading images for use on client

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Loading images for use on client

    Hi all,

    I'm having a problem loading images for later use in javascript on the
    client. In my code-behind, I'm using a stringbuilder object to build and
    populate a few javascript variables like : js.append("var myjsvariable = New
    Image")

    js.append("myjsvariable.src = " & "http://localhost/images" & "myimage.jpg")

    In one of my javascript functions, I reference this image and it is null.


    What am I doing wrong here?

    Regards
    John.


    John Guest

  2. Similar Questions and Discussions

    1. Loading Images
      Hi, I'm very new to Flash so please give me a break.... I want to load an image dynamically into a component using loadMovie theImage._width...
    2. [FMX] Loading images
      I have the following problem: On a on(release) event of a thumbnail the movie has to load an jpg which is in a map on website (pics). I have...
    3. images and loading
      hey, I am making a website (in flash) and i am animating a logo at the start, I have made the logo as a gif (It doesnt loose much quality). But i...
    4. Loading client-side images for use in Javascript
      Ok, I'll play the dumb guy.... if your script is running on the server under the testapp application, why isn't the source 'Images/down.gif' (Path...
    5. images not loading
      I've created a portfolio that works great when I create a regular Projector. But when I try to publish it and view the Shockwave file in a browser...
  3. #2

    Default Re: Loading images for use on client

    John,

    Are you then placing the string you've built in the client side code?

    I don't know which object you're trying to attach the javascript to, but it
    sounds like you are building the string on the server side but never placing
    the built string out on the client.

    For example if I want to add an attribute to a textbox I could build the
    string, but I then have to add the attribute to the client side code:

    Dim CodeBuilt As New System.Text.StringBuilder
    CodeBuilt.Append("MyStringHere")

    TextBox1.Attributes.Add("onClick", "javascript:" & CodeBuilt & ";")

    I'm assuming you will need to add your images to a script block so you might
    want to look into the Page.RegisterClientScriptBlock method.

    (Don't see RegisterClientScriptBlock in your intellisense? In .Net advanced
    members are hidden by default. To make them visible: Click Tools-Options,
    hen Select the "Text Editor" folder, then select the "All Languages" folder
    and you will see a grayed out check box "Hide advanced members" Click the
    checkbox to clear it. Alternatively you can select each language's specific
    folder and turn off the Hide advanced members feature per language.)

    I hope this helps.

    Justin




    "John" <a@b.com> wrote in message
    news:eEhcbpsSDHA.2252@TK2MSFTNGP12.phx.gbl...
    > Hi all,
    >
    > I'm having a problem loading images for later use in javascript on the
    > client. In my code-behind, I'm using a stringbuilder object to build and
    > populate a few javascript variables like : js.append("var myjsvariable =
    New
    > Image")
    >
    > js.append("myjsvariable.src = " & "http://localhost/images" &
    "myimage.jpg")
    >
    > In one of my javascript functions, I reference this image and it is null.
    >
    >
    > What am I doing wrong here?
    >
    > Regards
    > John.
    >
    >

    S. Justin Gengo Guest

  4. #3

    Default Re: Loading images for use on client

    Hi

    Basic Preloader:

    <script>
    iPreload(// Add images to preload here
    "myImg1.gif",
    "myImg2.gif"
    );

    var imgArr = new Array();
    function iPreload(){
    var p = "IMAGEPATH/";
    if( document.images )
    {
    for( i = 0; i < iPreload.arguments.length; i++ )
    {
    imgArr[ i ] = new Image();
    imgArr[ i ].src = p + iPreload.arguments[i];
    }
    }
    }
    </script>

    So if you want to set the src of a image to myImg1.gif
    document.images["IMAGENAME"].src = imgArr[0];
    document.images["IMAGENAME"].src = imgArr[1]; // myImg2.gif here

    --
    Best Regards
    Vidar Petursson
    ==============================
    Microsoft Internet Client & Controls MVP
    ==============================
    "John" <a@b.com> wrote in message
    news:eEhcbpsSDHA.2252@TK2MSFTNGP12.phx.gbl...
    > Hi all,
    >
    > I'm having a problem loading images for later use in javascript on the
    > client. In my code-behind, I'm using a stringbuilder object to build and
    > populate a few javascript variables like : js.append("var myjsvariable =
    New
    > Image")
    >
    > js.append("myjsvariable.src = " & "http://localhost/images" &
    "myimage.jpg")
    >
    > In one of my javascript functions, I reference this image and it is null.
    >
    >
    > What am I doing wrong here?
    >
    > Regards
    > John.
    >
    >

    Vidar Petursson Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139