My jQuery dialog won't open in the same place each time

My jQuery dialog won't open in the same place each time

I have a jQuery dialog in an asp.net MVC 4 app that opens with it's contents as expected but the first time it is an inch? lower on the screen than the subsequent openings. Each subsequent opening occurs in the same and preferred location higher up the page. This is a not yet complete fix for a worse problem where subsequent openings of the dialog, after being dragged, failed to center the dialog, and also introduced scrollbars and added empty space at the end of the page of the same size as the dialog. This at least fixes all of those problems. Here is my code:
  1. $(function () {
  2. $("#StatusData").dialog({
  3. autoOpen: false,
  4. modal: true,
  5. resizable: false,
  6. draggable: true,
  7. width: 800,
  8. show: {
  9. effect: "fade",
  10. duration: 100
  11. },
  12. hide: {
  13. effect: "fade",
  14. duration: 100
  15. },
  16. create: function (event, ui) {
  17. // Center the dialog each time it re-opens
  18. $(this).dialog('widget')
  19. .css({ position: 'fixed' })
  20. .position({ my: 'center', at: 'center', of: window, collision: 'fit' });
  21. },
  22. open: function (event, ui) {
  23. // Remove the closing 'x' from the toolbar and replace it with the text 'Close'
  24. $('.ui-dialog-titlebar-close')
  25. .removeClass("ui-dialog-titlebar-close")
  26. .html('<span style="float:right; margin-right: 10px; font-weight: normal;">Close</span>');
  27. }
  28. });
BTW, line 21 has absolutely no effect. I get the same apparent behavior whether or not it is there.

What am I missing, how do I get the dialog located at the same place each time?