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 3 ■ WEB FORMS WITH <strong>ASP</strong>.<strong>NET</strong> 51<br />

if (IsPostBack)<br />

{<br />

string strOperation = Request.Form["optOperation"];<br />

int nF = 0;<br />

Int32.TryParse(txtFirst.Text, out nF);<br />

int nS = 0;<br />

Int32.TryParse(txtSecond.Text, out nS);<br />

int nR = 0;<br />

if (strOperation == "Add")<br />

nR = nF + nS;<br />

else<br />

nR = nF - nS;<br />

litResult.Text = nR.ToString();<br />

}<br />

}<br />

}<br />

Now when you type the values into the text boxes <strong>and</strong> click the submit button, the<br />

server will return the response <strong>and</strong>—thanks to view state—maintain the value of the text<br />

boxes.<br />

Also, as <strong>ASP</strong>.<strong>NET</strong> generates client-side code, you will have buttons rendered<br />

within the browser anyway! Take a look at the resulting HTML in your browser, <strong>and</strong> you’ll<br />

see something like Listing 3-9.<br />

Listing 3-9. Viewing the Source Code of the Page in the Browser<br />

<br />

<br />

<br />

Untitled Page<br />

<br />

<br />

<br />

<br />

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

Saved successfully!

Ooh no, something went wrong!