Add some JavaScript code to set up an event handler that fires whenever a sprite collides with the border of the game window, and to change the sprite's direction:
<script language="javascript">
var _gameWindow;
// register our initialization function to execute
Sys.Application.add_load(onPageLoad);
function onPageLoad()
{
// set up our handler for border collisions
_gameWindow = $find("GameWindowExtender1");
_gameWindow.add_borderCollision(borderCollisionHandler);
}
function borderCollisionHandler(gw, args)
{
sprAsteroid = args;
var direction = _gameWindow.get_BorderCollisionDirection(sprAsteroid) * 45;
var newDirRandomness = Math.floor(Math.random()*60);
var newDirection = (direction + 150 + newDirRandomness) % 360;
sprAsteroid.set_Direction(newDirection);
}
</script>