10.02.2014 Views

Beginning Ajax With ASP.NET (2006).pdf

Create successful ePaper yourself

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

Chapter 9<br />

The code defined here should immediately be familiar to you from your experience with <strong>Ajax</strong>.<strong>NET</strong>. The<br />

pattern here is the same as with <strong>Ajax</strong>.<strong>NET</strong>. First, you must register the page with the Anthem.<strong>NET</strong> framework.<br />

Then you add the Anthem.Method attribute to your method. As stated above, the Multiply<br />

method requires two factors as arguments and returns the product.<br />

Now test the behavior by launching the page in the browser.<br />

Example 6: Direct Scripting (Micro-Content)<br />

Recall from the Magic<strong>Ajax</strong> section how you implemented the micro-content pattern. You will now<br />

implement the same pattern using Anthem.<strong>NET</strong>.<br />

This exercise uses Anthem.<strong>NET</strong> as well as some custom Cascading Style Sheet definitions to power the<br />

change in the user interface to give clues as to what is happening.<br />

The page will provide initial clues that parts of the page are editable by drawing a border over the text<br />

when the cursor hovers over the editable area. (You can refer back to Figure 9-10 to remind yourself of<br />

what this looks like.)<br />

The next clue is to change the appearance of the control when the user has placed this area of the page in<br />

“edit mode.” (Refer back to Figure 9-11 to see an example of this.)<br />

Finally when the focus is lost from the control Anthem.<strong>NET</strong> will contact the server and allow the back-end<br />

processing to persist the latest data. Under normal circumstances you would probably persist the data to<br />

a data store of some kind. For demonstration purposes, this exercise will simply store the information in<br />

Session state. This way, once you make a change to the data, you can navigate off the page and return to<br />

see your latest changes, but you avoid having to implement a data layer just for this example.<br />

Try It Out<br />

Using Direct Scripting<br />

Begin by adding a new web form to the solution, naming it DirectScripting.aspx. Now add the<br />

Anthem register directive to the page just under the directive.<br />

<br />

Next, add the following code within the tag:<br />

<br />

input<br />

{<br />

border:solid 1px #fff;<br />

}<br />

.focus<br />

{<br />

background-color:#eee;<br />

border:dashed 1px #ccc;<br />

}<br />

.blur<br />

{<br />

242

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

Saved successfully!

Ooh no, something went wrong!