Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Preload Images in Asp.Net 2.0. How can I do this?

Reply
Thread Tools

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

 
 
shapper
Guest
Posts: n/a
 
      11-25-2006
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

 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      11-25-2006
"shapper" <> wrote in message
news: 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...


 
Reply With Quote
 
 
 
 
shapper
Guest
Posts: n/a
 
      11-25-2006
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" <> wrote in message
> news: 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...


 
Reply With Quote
 
Mark Rae
Guest
Posts: n/a
 
      11-25-2006
"shapper" <> wrote in message
news: 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(".....", ".....");


 
Reply With Quote
 
Laurent Bugnion
Guest
Posts: n/a
 
      11-25-2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Preload images returned by an HttpHandler =?Utf-8?B?Q2FzcGE=?= ASP .Net 2 03-28-2007 12:36 AM
preload images from sql server ks ASP .Net 1 08-05-2006 07:13 AM
Preload TreeView images Mark ASP .Net Web Controls 2 02-14-2004 11:15 AM
preload images Morris HTML 5 11-14-2003 02:19 AM



Advertisments