471,571 Members | 1,040 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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

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

Nov 25 '06 #1
4 10254
"shapper" <md*****@gmail.comwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
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...
Nov 25 '06 #2
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
Mark Rae wrote:
"shapper" <md*****@gmail.comwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
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...
Nov 25 '06 #3
"shapper" <md*****@gmail.comwrote in message
news:11**********************@l39g2000cwd.googlegr oups.com...
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(".....", ".....");
Nov 25 '06 #4
Hi,

shapper wrote:
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
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Nov 25 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by DiggidyMack69 | last post: by
5 posts views Thread by hoolie | last post: by
1 post views Thread by ks | last post: by
2 posts views Thread by =?Utf-8?B?Q2FzcGE=?= | last post: by
3 posts views Thread by blobb | last post: by
9 posts views Thread by shapper | last post: by
2 posts views Thread by CK | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

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.