473,405 Members | 2,334 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,405 software developers and data experts.

Problem loading an image from client side code

Hello,

Having an issue with JavaScript in my ASP.Net page.

I use some COTS, which for all intents and purposes, simply makes a
jpeg file and physically places it in a directory on the web server.

The page load codebehind, makes a connection to the jpeg creation
service and gets the path of the newly created image.

The sample code I'm providing is very simple... no rocket science here.
Here's the code behind:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Dim j As New jpegImage ' removed code for COTS & replaced
with psuedocode for posting purposes.
Dim c As New serviceConnector ' removed code for COTS & replaced
with psuedocode for posting purposes.
Dim urlImage

c = Server.CreateObject("Connector") ' removed code for COTS &
replaced with psuedocode for posting purposes.
c.ServerName = "DC1" ' Server's name
c.ServerPort = 5300 ' Server's port

j = Server.CreateObject("Jpeg") ' removed code for COTS &
replaced with psuedocode for posting purposes.
urlImage = j.GetImageAsUrl() ' string with path to newly
created jpeg file on server

Me.mapImageSrc_hidden.Value = urlImage

End Sub

Okay... you'll see that I'm using a hidden field in the page markup.
There's a bunch of reasons for this madness I'll skip for now but I
need the client to load the image... not the server. Here's what
happens next:

<asp:HiddenField ID="mapImageSrc_hidden" runat="server" />
<img id="mapImage" src="Images/null.gif" onload="getImage();" />

And in here's the getImage method:

function getImage()
{
var objHiddenImage =
document.getElementById("mapImageSrc_hidden");
var objMapImage = document.getElementById("mapImage");

objMapImage.src = objHiddenImage.value;
}

The problem is on the last line of the getImage method... when I put
the hidden field's value in the src property of the html image, the
page gets stuck in an infinte loop. It's as if the page never fully
loads, even though image generation is complete on the server, so the
onload=getImage() keeps getting fired over and over again.

Adding a "return" to the function doesn't help... nor does checking for
top.PostBackDone. Additionally I tried putting the call in
window.onload...

<head>
<script type="text/javascript">
function getMap()
{
if (arguments.callee.done) return;

arguments.callee.done = true;
var objHiddenImage =
document.getElementById("mapImageSrc_hidden");
var objMapImage = document.getElementById("mapImage");

objMapImage.src = objHiddenImage.value;
}
window.onload = getMap;
</script>
</head>

On objMapImage.src = objHiddenImage.value, I get the "null is null or
not an object" error and the image doesn't show... even though
debugging clearly shows a valid path string in objHiddenImage.value!!!

Any suggestions are greatly appreciated.

Thanks!

Jan 24 '07 #1
11 1853
Lee
Adam Sandler said:
>Okay... you'll see that I'm using a hidden field in the page markup.
There's a bunch of reasons for this madness I'll skip for now but I
need the client to load the image... not the server.
The server never loads images.
They're always loaded by the client via a separate request back
to the server, so throw away all that nonsense and simply write
the URL of the image into the src attribute of the image.
--

Jan 24 '07 #2


On Jan 24, 1:02 pm, Lee <REM0VElbspamt...@cox.netwrote:
The server never loads images.
Your absolutely correct. And I didn't mean to imply otherwise.

However, the server creates the image at runtime. The client doesn't
have, nor will it ever have, knowledge of this runtime creation. So I
use the hidden field in ASP.NET as a container between the server side
and client side. The server side sends the url of the runtime image to
the hidden field and the client side traces the DOM to pull the value
out of the hidden field.
simply write the URL of the image into the src attribute of the image.
okay... but what's the difference between authoring some document.write
staments or objMapImage.src = objHiddenImage.value???

Jan 24 '07 #3
Lee
Adam Sandler said:
>
On Jan 24, 1:02 pm, Lee <REM0VElbspamt...@cox.netwrote:
>The server never loads images.

Your absolutely correct. And I didn't mean to imply otherwise.

However, the server creates the image at runtime. The client doesn't
have, nor will it ever have, knowledge of this runtime creation. So I
use the hidden field in ASP.NET as a container between the server side
and client side. The server side sends the url of the runtime image to
the hidden field and the client side traces the DOM to pull the value
out of the hidden field.
>simply write the URL of the image into the src attribute of the image.

okay... but what's the difference between authoring some document.write
staments or objMapImage.src = objHiddenImage.value???
Besides the fact that one will work?
--

Jan 24 '07 #4
Lee
Adam Sandler said:
>
On Jan 24, 1:02 pm, Lee <REM0VElbspamt...@cox.netwrote:
>The server never loads images.

Your absolutely correct. And I didn't mean to imply otherwise.

However, the server creates the image at runtime. The client doesn't
have, nor will it ever have, knowledge of this runtime creation. So I
use the hidden field in ASP.NET as a container between the server side
and client side.
The server side sends the url of the runtime image to
the hidden field and the client side traces the DOM to pull the value
out of the hidden field.
>simply write the URL of the image into the src attribute of the image.

okay... but what's the difference between authoring some document.write
staments or objMapImage.src = objHiddenImage.value???
No, you don't need document.write statements. Write the URL of your
generated src into the HTML when you generate the page on the server.
That src won't be accessed by the server, only by the client.
--

Jan 24 '07 #5
Lee
Lee said:
>
Adam Sandler said:
>>
On Jan 24, 1:02 pm, Lee <REM0VElbspamt...@cox.netwrote:
>>The server never loads images.

Your absolutely correct. And I didn't mean to imply otherwise.

However, the server creates the image at runtime. The client doesn't
have, nor will it ever have, knowledge of this runtime creation. So I
use the hidden field in ASP.NET as a container between the server side
and client side. The server side sends the url of the runtime image to
the hidden field and the client side traces the DOM to pull the value
out of the hidden field.
>>simply write the URL of the image into the src attribute of the image.

okay... but what's the difference between authoring some document.write
staments or objMapImage.src = objHiddenImage.value???

Besides the fact that one will work?
My news host won't seem to allow me to cancel this post.
--

Jan 24 '07 #6
VK


On Jan 24, 8:20 pm, "Adam Sandler" <cor...@excite.comwrote:
<img id="mapImage" src="Images/null.gif" onload="getImage();" />

And in here's the getImage method:

function getImage()
{
var objHiddenImage =
document.getElementById("mapImageSrc_hidden");
var objMapImage = document.getElementById("mapImage");

objMapImage.src = objHiddenImage.value;
}

The problem is on the last line of the getImage method... when I put
the hidden field's value in the src property of the html image, the
page gets stuck in an infinte loop.
Of course it does. This is from the "Top 10 of dummy errors in
JavaScript" :-)

Image loads and calls onload handler. Onload handler instructs to load
another image instead of the current one. New image loads and calls
onload handler. See the top... and so on...
With all <layers>, <iframesand <imgput in onload loop this way
since 1997 one could make a mountain with its paramount in the
stratosphere, so don't be ashamed - you are not the first and most
definitely not the last. :-)

out:
objMapImage.src = objHiddenImage.value;
in:
if (objMapImage.src != objHiddenImage.value) {
objMapImage.src != objHiddenImage.value;
}

P.S. More sophisticated ways with removing event listener on first call
are also possible.
Whatever you are doing with image load sequence seems very strange -
but OK, it is your doing.

Jan 24 '07 #7
Lee <RE**************@cox.netwrote in news:ep*********@drn.newsguy.com:
Adam Sandler said:
>>Okay... you'll see that I'm using a hidden field in the page markup.
There's a bunch of reasons for this madness I'll skip for now but I
need the client to load the image... not the server.

The server never loads images.
They're always loaded by the client via a separate request back
to the server, so throw away all that nonsense and simply write
the URL of the image into the src attribute of the image.
Learn to use server-side scripting properly, whether it's PHP, ASP,
ColdFusion or whatever.

Your server-side script generates an image and puts it in a file on your
server, right?

In your source code for the web page, you'll have something like this:

<img src="_insert_file_name_here_">

where "_insert_file_name_here_" means that your scripting language
outputs the actual name of the file between the quotes.

Compare: If your image is static in a file named myImage.jpg, you'd have

<img src="myImage.jpg">

Jan 25 '07 #8
Lee
NO said:
>
Lee <RE**************@cox.netwrote in news:ep*********@drn.newsguy.com:
>Adam Sandler said:
>>>Okay... you'll see that I'm using a hidden field in the page markup.
There's a bunch of reasons for this madness I'll skip for now but I
need the client to load the image... not the server.

The server never loads images.
They're always loaded by the client via a separate request back
to the server, so throw away all that nonsense and simply write
the URL of the image into the src attribute of the image.

Learn to use server-side scripting properly, whether it's PHP, ASP,
ColdFusion or whatever.

Your server-side script generates an image and puts it in a file on your
server, right?

In your source code for the web page, you'll have something like this:

<img src="_insert_file_name_here_">

where "_insert_file_name_here_" means that your scripting language
outputs the actual name of the file between the quotes.

Compare: If your image is static in a file named myImage.jpg, you'd have

<img src="myImage.jpg">
Note that you responded to my post, and not to the person with
the problem.
--

Jan 25 '07 #9
Lee <RE**************@cox.netwrote in news:ep********@drn.newsguy.com:
>
Note that you responded to my post, and not to the person with
the problem.
Yes, that's because I trimmed the quoted text. But my reply was intended
to enlighten the original poster, not you. No offense.
Jan 25 '07 #10
Lee
NO said:
>
Lee <RE**************@cox.netwrote in news:ep********@drn.newsguy.com:
>>
Note that you responded to my post, and not to the person with
the problem.

Yes, that's because I trimmed the quoted text. But my reply was intended
to enlighten the original poster, not you. No offense.
No offense taken, but you risk having the OP ignore your post, because
it appears to be directed to me.
--

Jan 25 '07 #11


Lee and VK... thanks for the replies.

Jan 26 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: kieran5405 | last post by:
Hi, I have an Intranet page that has an image that changes each day, but the image is caching and not updating until the user manually does a page refresh. I want the page to refresh itself but...
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...
11
by: Abhishek | last post by:
I have a problem transfering files using sockets from pocket pc(.net compact c#) to desktop(not using .net just mfc and sockets 2 API). The socket communication is not a issue and I am able to...
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...
8
by: nick | last post by:
I have a problem and I've been using a cheezy work around and was wondering if anyone else out there has a better solution. The problem: Let's say I have a web application appA. Locally, I set...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
23
by: Peter | last post by:
I have a problem with a page show_image.asp that returns a jpg image under Windows XP Pro SP2. The page sets content type as: Response.ContentType = "image/jpg" While this works perfectly fine...
5
by: toffee | last post by:
Hi all, I've seen a really cool effect which i would like to use on an intranet site. Am referring to the 'LOADING..' animation you see when switching pages. I've seen it somewhere on a website...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.