views:

337

answers:

1

I have an asp.net-mvc site and I use the below javascript library for a photos page to put borders around all of my photos

http://www.netzgesta.de/instant/

i just changed my site to load my photos via ajax instead of reloading the whole page and although when i debug it the correct html is built up, i dont see any of the images:

<div id="status">
    <% Html.RenderPartial("AlbumGrid",Model); %>
</div>

the change i made was to take all of the links like this:

<a href='Album?Page=" + i + "&AlbumName=" + albumName_ + "'>" + i + "</a>");

and change it to this and using ajaxhelper class:

 Ajax.ActionLink(i.ToString(), "Album?Page=" + i + "&AlbumName=" + albumName_, new AjaxOptions { UpdateTargetId = "status", LoadingElementId = "updating"}));

I know it has something to do with this instant.js library because it breaks when i have this:

<img class=\"instant ishadow50\"  src=\"...">

but if i remove the class above, and just load images regularly, everything works fine (but i dont get the border effect of course). So this below works fine.

<img   src=\"...">

Has anyone tried using this library with ajax successfully?


EDIT: I have added full source below (stripping down to the minimum):

<head>
    <script type='text/javascript' src='../../Scripts/jquery-1.3.2.js'></script>
    <script type="text/javascript" src="../../Scripts/instant.js"></script>
<script type="text/javascript" src="../../Scripts/cvi_instant_lib.js"></script>
<script type="text/javascript" src="../../Scripts/MicrosoftAjax.js"></script>
<script type="text/javascript" src="../../Scripts/MicrosoftMvcAjax.js"></script>

<script type="text/javascript">
    function done() {
        alert('done');
    }
</script>

<script type="text/javascript">
<!--
        var canvascheck = document.createElement('canvas');
        if (canvascheck.getContext || (document.all && document.namespaces && !window.opera)) {
            document.writeln('<style type="text/css">');
            document.writeln('img.instant { visibility: hidden; }');
            document.writeln('<\/style>');
            }
-->
</script>
</head>

<body >
<center>

<div id="status">
    <table width="750" cellspacing="0" cellpadding="10" rules="all" border="1"      style="background-color:#EEEEEE;width:750px;border-collapse:collapse;">
<tr align="center">
<td width="187.5" valign="top">
<a id="picLinks_0" class="picLinks" href=''><img class="instant ishadow50" id='001'  src="http://adam.kantro.net/pics/Jersey_Shore_1/Thumbnails/Jersey_Shore_1-  pic001.jpg"></img></a>
<br/>

</td>
<td width="187.5" valign="top">
<a id="picLinks_1" class="picLinks" href=''><img class="instant ishadow50" id='002'  src="http://adam.kantro.net/pics/Jersey_Shore_1/Thumbnails/Jersey_Shore_1-pic002.jpg"&gt;&lt;/img&gt;&lt;/a&gt;
<br/>
</td>
<td width="187.5" valign="top">
<a id="picLinks_2" class="picLinks" href=''><img class="instant ishadow50" id='003'  src="http://adam.kantro.net/pics/Jersey_Shore_1/Thumbnails/Jersey_Shore_1-pic003.jpg"&gt;&lt;/img&gt;&lt;/a&gt;
<br/>
</td>
<td width="187.5" valign="top">
<a id="picLinks_3" class="picLinks" href=''><img class="instant ishadow50" id='004'  src="http://adam.kantro.net/pics/Jersey_Shore_1/Thumbnails/Jersey_Shore_1-pic004.jpg"&gt;&lt;/img&gt;&lt;/a&gt;
<br/>
</td>
</tr>
<tr align="center">
<td width="187.5" valign="top">
<a id="picLinks_4" class="picLinks" href=''><img class="instant ishadow50" id='005'  src="http://adam.kantro.net/pics/Jersey_Shore_1/Thumbnails/Jersey_Shore_1-pic005.jpg"&gt;&lt;/img&gt;&lt;/a&gt;

<br/>
</td>
<td width="187.5" valign="top">
<a id="picLinks_5" class="picLinks" href=''><img class="instant ishadow50" id='006'  src="http://adam.kantro.net/pics/Jersey_Shore_1/Thumbnails/Jersey_Shore_1-pic006.jpg"&gt;&lt;/img&gt;&lt;/a&gt;
<br/>
</td>
</tr>
</table>
</div>

<img id="updating" src="../../images/ajax-loader.gif" style="display: none;" alt="Updating ..." />

<br />
      <div id="paging">
       Page: 1 of 9&nbsp;&nbsp;&nbsp;  1 
<a href="/Photos/Album?Page=2&amp;AlbumName=Jersey_Shore_1" onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, loadingElementId: 'updating', updateTargetId: 'status', onSuccess: Function.createDelegate(this, done) });">2</a>
<a href="/Photos/Album?Page=3&amp;AlbumName=Jersey_Shore_1" onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, loadingElementId: 'updating', updateTargetId: 'status', onSuccess: Function.createDelegate(this, done) });">3</a>

<a href="/Photos/Album?Page=4&amp;AlbumName=Jersey_Shore_1" onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, loadingElementId: 'updating', updateTargetId: 'status', onSuccess: Function.createDelegate(this, done) });">4</a>
<a href="/Photos/Album?Page=5&amp;AlbumName=Jersey_Shore_1" onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, loadingElementId: 'updating', updateTargetId: 'status', onSuccess: Function.createDelegate(this, done) });">5</a>
 <a href="/Photos/Album?Page=6&amp;AlbumName=Jersey_Shore_1" onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, loadingElementId: 'updating', updateTargetId: 'status', onSuccess: Function.createDelegate(this, done) });">6</a>
 <a href="/Photos/Album?Page=7&amp;AlbumName=Jersey_Shore_1" onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, loadingElementId: 'updating', updateTargetId: 'status', onSuccess: Function.createDelegate(this, done) });">7</a>
 <a href="/Photos/Album?Page=8&amp;AlbumName=Jersey_Shore_1" onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, loadingElementId: 'updating', updateTargetId: 'status', onSuccess: Function.createDelegate(this, done) });">8</a>
 <a href="/Photos/Album?Page=9&amp;AlbumName=Jersey_Shore_1" onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, loadingElementId: 'updating', updateTargetId: 'status', onSuccess: Function.createDelegate(this, done) });">9</a>

  Next >>

    </div>
</div>        
</body>
</html>
+2  A: 

Your problem happens because instant.js works automatically when the page loads. When you load images with AJAX, the images load after the page has fully loaded and after instant have finished working.

Instead of instant.js, use cvi_instant_lib.js and after each image you load with AJAX call cvi_instant to "fix" your images. You can find instructions on instant's web site for how to do this.

Guss
thanks . . i see this page http://visualize.theforbiddenlibido.com/odd_ftp/examples/instant-js/code-samples.htmlbut how would i add it when the ajax is complete
ooo
You'd need to write Javascript that runs after the AJAX command complete. I'm not familiar with your AJAX framework so I can't suggest something more specific.
Guss
ok, i am using ajaxhelper so i added an oncomplete in the ajaxoptions tags and can get a javascript callback.. in the callback i put cvi_instant.modify(document.getElementById("001"), { tilt: "left" }); but i still dont see any of the images
ooo
Does the IMG tag has an ID "001" ? Please make sure that the ID you assign to the image is unique, otherwise getElementById() will not behave well. Can you show me an the app you are working on (or a minimal example) - I can help more if I can refer to specific code.
Guss
i have added full source code above to review if that helps. right now i just put an alert in the "done" method to prove that its being called (which it is) but when i put in the cvi_instant . . line nothing seems to happen
ooo
Sorry, but I don't see the code you are referring to. Except for the lots of javascript at the end with "mvc" all over the place (which I don't understand what it does), I also do not see any dynamic code there - instant should work fine on the images you have in the code.
Guss
page 1 works fine but as i click on the paging links at the bottom it refreshes the whole table with the new set of pictures . . this is the issue where nothing comes up
ooo
Yes, I got that - I just don't understand how its done. I don't understand how the paging links work and I don't see any function that gets called after the new page is loaded. You should have some function that the Ajax code will call after the new page has been loaded, and that function should go over all the images and attach the instant classes to them using cvi.
Guss
ooo
this (comment above) is the Ajax link (using ms ajaxhelper). as you can see the method "done" is called after the ajax is loaded
ooo
I see - and I see that `done()` issues as `alert`. Is the alert being shown?
Guss
yes . . when i just put in an alert it shows . .
ooo
Cool, then just add a code that does `getElementsByTagName('img')` and for each image check if its id starts with `picLinks` and if it does run `cvi_instant.add(img, { <options> } );` on it. Should work nicely.
Guss
thanks . .its working now . .
ooo
Great! Good luck, and thanks :-)
Guss