08.01.2015 Views

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

274<br />

CHAPTER 11 ■ <strong>AJAX</strong> APPLICATIONS AND EMPOWERING THE WEB USER EXPERIENCE<br />

Finally, you need to wire up the event h<strong>and</strong>lers for the buttons, allowing navigation<br />

through the images. It’s pretty straightforward—you simply increment or decrement the<br />

current picture ID <strong>and</strong> then call ShowPic with the new ID:<br />

function DoPrev()<br />

{<br />

currentPic--;<br />

ShowPic(currentPic);<br />

}<br />

function DoNext()<br />

{<br />

currentPic++;<br />

ShowPic(currentPic);<br />

}<br />

And that’s it. You now have an Ajax page with forward (<strong>and</strong> backward) caching of<br />

images. You can streamline this page if you like—when you think about it, Ajax isn’t necessary<br />

for the ShowPage call—you could simply construct an tag from the current<br />

pic, but it is good to underst<strong>and</strong> the technique, as you will use it in more complex apps.<br />

You can see the application in action in Figures 11-8 <strong>and</strong> 11-9. The latter is the result<br />

of clicking the >> button shown in Figure 11-8. As you run the application, you’ll see how<br />

quickly the pictures update <strong>and</strong> render.<br />

Figure 11-8. Running the forward-caching Ajax application

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!