03.11.2016 Views

Beginning ASP.NET 4.5 in CSharp and VB Opsylum

Create successful ePaper yourself

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

780 x APPENDIX A EXERCISE ANSWERS<br />

Exercise 2 Solution<br />

The slideUp method hides elements by slowly decreas<strong>in</strong>g their height. slideDown shows hidden elements<br />

<strong>in</strong>stead by do<strong>in</strong>g the reverse: slowly <strong>in</strong>creas<strong>in</strong>g the height of an element until it’s fully visible.<br />

Both methods accept, among other arguments, a speed parameter that either accepts a fixed value<br />

(slow, normal, or fast) or a number specify<strong>in</strong>g the speed of the animation <strong>in</strong> milliseconds.<br />

Exercise 3 Solution<br />

jQuery’s document ready function fires when the page is f<strong>in</strong>ished load<strong>in</strong>g <strong>in</strong> the browser, only dur<strong>in</strong>g<br />

the <strong>in</strong>itial request. The pageLoad method fires both when the page first loads <strong>and</strong> after an asynchronous<br />

postback, for example, when us<strong>in</strong>g an UpdatePanel. This difference enables you to choose<br />

the desired behavior. Need to fire some code on <strong>in</strong>itial load <strong>and</strong> after a postback? Choose pageLoad.<br />

Otherwise, choose jQuery’s document ready function.<br />

Exercise 4 Solution<br />

You use the special _references.js file <strong>in</strong> the Scripts folder to enable IntelliSense. VS will read<br />

this file <strong>and</strong> parse all JavaScript files that you added with this syntax:<br />

/// <br />

This way, you get IntelliSense <strong>in</strong> files where it would otherwise not be supported (such as user controls)<br />

or for JavaScript files that you’re not directly l<strong>in</strong>k<strong>in</strong>g to <strong>in</strong> your website.<br />

CHAPTER 12<br />

Exercise 1 Solution<br />

The DELETE statement fails because there is a relationship between the Id of the Genre table <strong>and</strong> the<br />

GenreId of the Review table. As long as this relationship is <strong>in</strong> effect, you cannot delete genres that<br />

still have reviews attached to them. To be able to delete the requested genre, you need to delete the<br />

associated reviews first, or assign them to a different genre us<strong>in</strong>g an UPDATE statement. Exercise 4<br />

shows you how you can accomplish this.<br />

Exercise 2 Solution<br />

The relationship between the Genre <strong>and</strong> Review tables is a one-way relationship. The relationship<br />

enforces that the GenreId assigned to a review must exist as an Id <strong>in</strong> the Genre table. At the same<br />

time, it blocks you from delet<strong>in</strong>g genres that have reviews attached to them. However, the relationship<br />

doesn’t stop you from delet<strong>in</strong>g rows from the Review table.<br />

Exercise 3 Solution<br />

To delete reviews with an Id of 100 or less, you need the follow<strong>in</strong>g SQL statement:<br />

DELETE FROM Review WHERE Id

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

Saved successfully!

Ooh no, something went wrong!