By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,650 Members | 1,815 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,650 IT Pros & Developers. It's quick & easy.

Loading images for use on client

P: n/a
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.
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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:eE**************@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.

Nov 17 '05 #2

P: n/a
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:eE**************@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.

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.