473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.
Nov 17 '05 #1
2 1727
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: OneSolution | last post by:
Hi All, Here's what I'm trying to do. I have a diverse customer base, and as it grows, it's increasingly harder to figure out what aspect of our web site is selling and what is not. So I've...
6
by: Ed | last post by:
I first noticed this in my own app. Images would show up missing randomly on IE 6.0.2800.1106 on Windows 2000 server. I then was able to repro this problem on Microsoft's website!!! The page I...
4
by: Adrian MacNair | last post by:
Hi, I created an image gallery which displays 63 images in a slideshow. The problem is that the show was slow because each image loaded one at a time during the show. No problem right? I just...
5
by: vanisathish | last post by:
Hi I have an application, which has to change to different images based on some conditions. I am trying to call a javascript function(this function changes the images on the front end) from the...
4
by: sef | last post by:
i have a server-side script that executes this: linkbutton1.Attributes.Add("onClick", "linkClicked();"); the client-side code has an html image control <img id="image1"> the client-side...
1
by: Chris Kerrison | last post by:
I have a Webpage that dynamically loads a series of thumbnail images from a SQL database into a placeholder. The problem I have is that the page displays before all the images have been populated...
5
by: Cenk Genisol | last post by:
Hi NG, I am relatively new to Web developement and have some questions to you. I've got a Masterpage where some graphics are embedded by CSS. They format the borders of tables, which store...
6
by: vunet | last post by:
This may be a strange question from a non-technical person who asked me to make his whole site and images load all at once. I.e. the completely loaded site would show up immediately even with a big...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.