Wednesday, March 21, 2012

UpdatePanel and Javascript - Preload Images?

Im having a problem,

When i use the following javascript in the <head runat="server">... other head items..

<

SCRIPTtype="text/javascript"LANGUAGE="JavaScript">

<!-- Begin
image1 =

new Image();

image1.src =

"/images/header.jpg";

// End -->

</script>

</head>

That code seems to break the timer and updatepanel. Any ideas? I see no errors on the client side, except that it doesnt update on the interval I've chosen, but when i remove the preloader code it works. ?!? Anyone have work arounds?

Try putting the script in an external .js file and reference that file in the scriptmanager:

<atlas:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering=true>

<Scripts><atlas:ScriptReferencePath="/inc/helperscripts.js"/></Scripts></atlas:ScriptManager>

philmccracken:

Try putting the script in an external .js file and reference that file in the scriptmanager:

<atlas:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering=true>

<Scripts><atlas:ScriptReferencePath="/inc/helperscripts.js"/></Scripts></atlas:ScriptManager>

Hmm, I do that and now I get object not found error in IE. (line 2,123 something..) I see the correct reference in the HTML output. If you wish to check that implementation its onwww.smackfm.com, perhaps Im using wrong way to implement Preloading of images and its causing the timer to break?


Can you run javascript on the fly in an external script file? (I don't know, I've never tried). Maybe you need to put that inside a function and then run the function? Either by adding an onload to the body tag, or maybe with page.registerstartupscript? I'd play around with it... (Unless someone wants to post that knows for sure...)


try thisDevil [666]
<script type="text\javascript"> var img = new Image(); img.src = "/images/header.jpg";</script>

No comments:

Post a Comment