03.11.2016 Views

Beginning ASP.NET 4.5 in CSharp and VB Opsylum

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 10 x 777<br />

CHAPTER 10<br />

Exercise 1 Solution<br />

The ScriptManager control is a required component <strong>in</strong> almost all Ajax-related operations. It takes<br />

care of register<strong>in</strong>g client-side JavaScript files, h<strong>and</strong>les <strong>in</strong>teraction with web services def<strong>in</strong>ed <strong>in</strong> your<br />

website, <strong>and</strong> it’s responsible for the partial page updates. You usually place the ScriptManager<br />

directly <strong>in</strong> a content page if you th<strong>in</strong>k you need Ajax capabilities on only a h<strong>and</strong>ful of pages.<br />

However, you can also place the ScriptManager <strong>in</strong> a master page so it becomes available throughout<br />

the entire site.<br />

When you have the ScriptManager <strong>in</strong> the master page you can use the ScriptManagerProxy to<br />

register <strong>in</strong>dividual web services or script files on content pages. Because you can have only one<br />

ScriptManager <strong>in</strong> a page, you can’t add another one <strong>in</strong> a content page that uses your master page<br />

with the ScriptManager. The ScriptManagerProxy serves as a bridge between the content page<br />

<strong>and</strong> the ScriptManager, giv<strong>in</strong>g you great flexibility as to where you register your services.<br />

Exercise 2 Solution<br />

You can let your users know a partial page update is <strong>in</strong> progress by add<strong>in</strong>g an UpdateProgress control<br />

to the page. You connect this control to an UpdatePanel us<strong>in</strong>g its AssociatedUpdatePanelID.<br />

Inside the you def<strong>in</strong>e whatever markup you see fit to <strong>in</strong>form your user<br />

an update is <strong>in</strong> progress. A typical conta<strong>in</strong>s an animated icon, some text,<br />

or both.<br />

Exercise 3 Solution<br />

To create a script-callable service, you first need to add an AJAX-enabled WCF service file to<br />

your site us<strong>in</strong>g the Add New Item dialog box. The class file that is created for you already has the<br />

ServiceContract <strong>and</strong> AspNetCompatibilityRequirements attributes applied.<br />

<strong>VB</strong>.<strong>NET</strong><br />

<br />

<br />

Public Class NameOfYourService<br />

C#<br />

[ServiceContract(Namespace = "")]<br />

[AspNetCompatibilityRequirements(<br />

RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]<br />

public class NameOfYourService<br />

You then need to decorate each method with<strong>in</strong> this class that you want exposed as a web method<br />

with the OperationContract attribute:

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

Saved successfully!

Ooh no, something went wrong!