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

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

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

CHAPTER 12 ■ <strong>AJAX</strong> EXTENSIONS FOR <strong>ASP</strong>.<strong>NET</strong> 289<br />

Migrating <strong>ASP</strong>.<strong>NET</strong> to <strong>AJAX</strong><br />

One of the nicest things about <strong>ASP</strong>.<strong>NET</strong> <strong>AJAX</strong> is the fact that the UpdatePanel control<br />

can be used to add <strong>AJAX</strong> functionality to an existing <strong>ASP</strong>.<strong>NET</strong> application. This is simply<br />

achieved by wrapping the relevant controls with an UpdatePanel.<br />

Consider the following example. Add a new web form to your application <strong>and</strong> call it<br />

AddWithUpdatePanel.aspx. On this form, add a couple of text boxes, a button, <strong>and</strong> a label,<br />

<strong>and</strong> call them txtA, txtB, btnAdd, <strong>and</strong> lblAns, respectively. The source of your page should<br />

look like this:<br />

<br />

<br />

<br />

<br />

Untitled Page<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

&nbsp;<br />

<br />

<br />

<br />

Double-click the button to add an event h<strong>and</strong>ler, <strong>and</strong> add the following code to it:<br />

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

{<br />

int a = Convert.ToInt16(txtA.Text);<br />

int b = Convert.ToInt16(txtB.Text);

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

Saved successfully!

Ooh no, something went wrong!