10.02.2014 Views

Beginning Ajax With ASP.NET (2006).pdf

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

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

Other <strong>Ajax</strong> Frameworks for .<strong>NET</strong><br />

The block of JavaScript is responsible for gathering the user input and passing it to the Anthem_Invoke<br />

PageMethod function. The first argument in this function is the name of the method on the server that<br />

you want to execute. In an upcoming code block, you will define a method on the page named Multiply,<br />

which is the code this function will execute. The next argument is an array of values that represent the signature<br />

of the Multiply method on the server. Multiply requires two integers to multiply together and<br />

returns the result. The final argument is the address of the callback function. After Multiply_CallBack<br />

runs, the textbox txtResult’s value will contain the product of the two numbers.<br />

You will not add the Anthem page directive to the page in this example. The technique used here will<br />

use Anthem.<strong>NET</strong>’s functionality to access methods in the code-behind directly from JavaScript. This<br />

approach does not require that you use Anthem.<strong>NET</strong> controls.<br />

Next, update the markup by adding the following code between the tags:<br />

<br />

X<br />

<br />

<br />

<br />

The HTML you see here is a bit different from the type of markup you have defined in the previous<br />

examples. In this case, you are not using a panel, nor are you declaring your controls as custom controls.<br />

This approach uses JavaScript to directly access the code-behind methods. Each input box is a standard<br />

HTML input box, and the work begins when you click the Multiply button.<br />

Finally, update the InvokePageMethod class with the following code-behind:<br />

public partial class InvokePageMethod : System.Web.UI.Page<br />

{<br />

protected void Page_Load(object sender, EventArgs e)<br />

{<br />

Anthem.Manager.Register(this);<br />

}<br />

}<br />

[Anthem.Method]<br />

public int Multiply(int int1, int int2)<br />

{<br />

return (int1 * int2);<br />

}<br />

241

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

Saved successfully!

Ooh no, something went wrong!