Preload Images in Asp.Net 2.0. How can I do this?

S

shapper

Hello,

I am working in Asp.Net 2.0 web sites and I need to preload some images
in my master pages and in the pages that use those master pages.

Could someone tell me how to do this?

Thanks,

Miguel
 
M

Mark Rae

I am working in Asp.Net 2.0 web sites and I need to preload some images
in my master pages and in the pages that use those master pages.

Could someone tell me how to do this?

I'm not sure what you mean by "preload some images"...

Maybe you're slightly confused about what MasterPages are or, more
importantly, what they're not - they're certainly not some sort of new
version of a frameset. The content pages aren't like iframes or anything
like that. MasterPages are, in fact, not pages at all - they are
UserControls which allow content pages to share the same look and feel etc.
However, each time a content page is requested, it ASP.NET builds the entire
page from the beginning, surrounding the content page with the MasterPage's
markup. There is nothing "preloaded", as such...
 
S

shapper

Hi,

Maybe I am explaining it wrong.
I am creating a custom control which given a list of images generates
the javascript code and add it to a page so the images are preloaded.

I want to use it in my master pages or in my pages.

Now i am looking for the right javascript code. Any ideas?

I also need to check if I can use it in a Master Page.
I know that I need to add the javascript code to the page. That's ok.
The problem is that I also need to add some code to the Html body tag.

Something like <body onload="...">

Any idea of how to do this?

Thanks,
Miguel
 
M

Mark Rae

Maybe I am explaining it wrong.
I am creating a custom control which given a list of images generates
the javascript code and add it to a page so the images are preloaded.

Hmm - still don't know what you mean by "preloaded" - a page is loaded when
it's requested, unlike e.g. a WinForm which *can* be preloaded and then made
visible at a later date...
Now i am looking for the right javascript code. Any ideas?

Not till you actually explain what you're trying to do...
The problem is that I also need to add some code to the Html body tag.

Something like <body onload="...">

Any idea of how to do this?

<body id="MyBodyTag" runat="server">

MyBodyTag.Attributes.Add(".....", ".....");
 
L

Laurent Bugnion

Hi,
Hi,

Maybe I am explaining it wrong.
I am creating a custom control which given a list of images generates
the javascript code and add it to a page so the images are preloaded.

I want to use it in my master pages or in my pages.

Now i am looking for the right javascript code. Any ideas?

I also need to check if I can use it in a Master Page.
I know that I need to add the javascript code to the page. That's ok.
The problem is that I also need to add some code to the Html body tag.

Something like <body onload="...">

Any idea of how to do this?

Thanks,
Miguel

Here are a few hints to get you started.

You preload images in JavaScript using the Image object. You use the
onload event to check when an image is correctly fully loaded. You use
the onerror object to check when an error occurs (for example when an
image is not found.

The onload and onerror event handlers cannot take parameters. Either you
don't need them (for example, you decide that if one error occurs, then
the whole page is invalid), or you can use closure to pass parameters to
the handling function anyway.

Example:

var myImage = new Image();
myImage.onload = imageOnLoad;
myImage.onerror = imageOnError;
myImage.src = "myimage.gif"; // This is the line starting the request

with:

function imageOnLoad()
{
writeStatus( "One image loaded, only " + iImages-- + " to go..." );
}

function imageOnError()
{
alert( "Big problem" );
}

HTH,
Laurent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top