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

Discussion in 'ASP .Net' started by shapper, Nov 25, 2006.

  1. shapper

    shapper Guest

    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
     
    shapper, Nov 25, 2006
    #1
    1. Advertising

  2. shapper

    Mark Rae Guest

    "shapper" <> wrote in message
    news:...

    > 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...
     
    Mark Rae, Nov 25, 2006
    #2
    1. Advertising

  3. shapper

    shapper Guest

    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:...
    >
    > > 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...
     
    shapper, Nov 25, 2006
    #3
  4. shapper

    Mark Rae Guest

    "shapper" <> wrote in message
    news:...

    > 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(".....", ".....");
     
    Mark Rae, Nov 25, 2006
    #4
  5. 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
     
    Laurent Bugnion, Nov 25, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Morris

    preload images

    Morris, Nov 12, 2003, in forum: HTML
    Replies:
    5
    Views:
    625
    Beauregard T. Shagnasty
    Nov 14, 2003
  2. ks
    Replies:
    1
    Views:
    390
    Mark Rae
    Aug 5, 2006
  3. =?Utf-8?B?Q2FzcGE=?=

    Preload images returned by an HttpHandler

    =?Utf-8?B?Q2FzcGE=?=, Mar 9, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    411
    Chilumba Mubashi [MSFT]
    Mar 28, 2007
  4. Mark

    Preload TreeView images

    Mark, Feb 13, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    214
    Teemu Keiski
    Feb 14, 2004
  5. Brynn

    Preload images question

    Brynn, Aug 19, 2004, in forum: ASP General
    Replies:
    1
    Views:
    117
    Ray at
    Aug 19, 2004
Loading...

Share This Page